Skip to content

Instantly share code, notes, and snippets.

@n9986
Created June 7, 2012 16:24
Show Gist options
  • Save n9986/2889864 to your computer and use it in GitHub Desktop.
Save n9986/2889864 to your computer and use it in GitHub Desktop.
Image Loading tip for Webkit browsers
/*
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