Como puedo saber el tamaño de una imagen con jquery
AUTOR PREGUNTA #1
<img src="mifoto.jpg" width="300" height="250" id="mifoto" />
-
2 personas más tuvieron esta duda Yo también
Esto también te interesa!
PREGUNTAS SIMILARES
#2
Supongamos tu imagen
<img src="mifoto.jpg" width="300" height="250" id="mifoto" />
Para averiguar el tamaño original de la imagen, primero eliminamos los atributos (width, heitght) actuales de la imagen con la función removeAttr(), y listo, ya podemos aplicar ahora las funciones width() y height() y obtendremos el tamaño real de la imagen:
$(window).load(function() { var imagen = $('#mifoto'); imagen.removeAttr("width"); // quitamos el atributo width imagen.removeAttr("height"); // quitamos el atributo height alert( imagen.width() ); // ancho original. Ej. 800 alert( imagen.height() ); // alto original. Ej: 600 });