Skip to content

Instantly share code, notes, and snippets.

@kihlstrom
Forked from johan/jquery.naturalWidth.js
Last active September 28, 2017 01:25
Show Gist options
  • Save kihlstrom/8316718 to your computer and use it in GitHub Desktop.
Save kihlstrom/8316718 to your computer and use it in GitHub Desktop.
// jQuery.naturalWidth / jQuery.naturalHeight plugin for (already-loaded) images
// Triple-licensed: Public Domain, MIT and WTFPL license - share and enjoy!
(function($) {
function img(url) {
var i = new Image;
i.src = url;
return i;
}
if ('naturalWidth' in (new Image)) {
$.fn.naturalWidth = function() { return this[0].naturalWidth; };
$.fn.naturalHeight = function() { return this[0].naturalHeight; };
return;
}
$.fn.naturalWidth = function() { return img(this[0].src).width; };
$.fn.naturalHeight = function() { return img(this[0].src).height; };
})(jQuery);
@kihlstrom
Copy link
Author

Added a fix to the original in order to make this work in Internet Explorer 8... :)

@temon
Copy link

temon commented Jun 9, 2014

nice...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment