-
-
Save kihlstrom/8316718 to your computer and use it in GitHub Desktop.
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
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added a fix to the original in order to make this work in Internet Explorer 8... :)