Se selezioni un'immagine con jQuery e poi usi .width()
, otterrai la larghezza corrente dell'immagine, anche se è stata ridimensionata (es. Larghezza massima: 100%;). Puoi accedere alla larghezza nativa delle immagini (anche se non ha attributi che la dichiarino) in questo modo:
// Get on screen image var screenImage = $("#image"); // Create new offscreen image to test var theImage = new Image(); theImage.src = screenImage.attr("src"); // Get accurate measurements from that. var imageWidth = theImage.width; var imageHeight = theImage.height;