Posted By

taifun on 10/16/11


Tagged

jquery preloading


Versions (?)

Get Image Dimensions


 / Published in: JavaScript
 

URL: http://css-tricks.com/snippets/jquery/get-an-images-native-width/

  1. // Get on screen image
  2. var screenImage = $("#image");
  3.  
  4. // Create new offscreen image to test
  5. var theImage = new Image();
  6. theImage.src = screenImage.attr("src");
  7.  
  8. // Get accurate measurements from that.
  9. var imageWidth = theImage.width;
  10. var imageHeight = theImage.height;

Report this snippet  

You need to login to post a comment.