Created
June 7, 2012 16:24
-
-
Save n9986/2889864 to your computer and use it in GitHub Desktop.
Image Loading tip for Webkit browsers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Webkit browsers set the height and width property after the image is loaded. | |
This results in zero being returned on trying to get the height and width. | |
So to get the right width and height using Javascript/jQuery | |
(.height() and .width()) consider using a img loaded callback as shown in the | |
example below. | |
*/ | |
$('img').load(function() { | |
// These will not return zero | |
var width = $(this).width(); | |
var height = $(this).height(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment