Last active
August 29, 2015 14:02
-
-
Save cbourdage/126850247f468f734710 to your computer and use it in GitHub Desktop.
Image min height and width detection
This file contains hidden or 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
| /** | |
| * Compares the images natural height and width with a provided | |
| * minimum height and width to check against. Fires callback if | |
| * valid | |
| * | |
| * @param $img jQuery Object | |
| * @param minH integer | |
| * @param minW integer | |
| * @param fn function | |
| */ | |
| imageZoomDetection: function($img, minH, minW, fn) { | |
| if (!$img.attr('href')) return; | |
| var _img = new Image(); | |
| _img.onload = function() { | |
| var width = this.naturalWidth ? this.naturalWidth : this.width, | |
| height = this.naturalHeight ? this.naturalHeight : this.height; | |
| if (height > minH && width > minW) { | |
| fn(); | |
| } | |
| }; | |
| _img.src = $img.attr('href'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment