Skip to content

Instantly share code, notes, and snippets.

@cbourdage
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save cbourdage/126850247f468f734710 to your computer and use it in GitHub Desktop.

Select an option

Save cbourdage/126850247f468f734710 to your computer and use it in GitHub Desktop.
Image min height and width detection
/**
* 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