Skip to content

Instantly share code, notes, and snippets.

@danielwrobert
Created November 22, 2013 00:31
Show Gist options
  • Save danielwrobert/7592569 to your computer and use it in GitHub Desktop.
Save danielwrobert/7592569 to your computer and use it in GitHub Desktop.
Resize images in a gallery list that are too tall - adjusts the height and centers accordingly. *** Not complete - TESTING ***
// GALLERY IMAGE RESIZER
var getMaxOfArray = function(numArray) {
return Math.max.apply(null, numArray);
};
var getMinOfArray = function(numArray) {
return Math.min.apply(null, numArray);
};
var galleryImageSize = function(selector) {
var imgList = [];
// loop through images and get the height of each into an array
$(selector).each(function(i,v) {
var $this = $(this),
imgHeight = $(this).height();
imgList.push(imgHeight);
if(imgHeight > getMinOfArray(imgList)) {
$this.css({
"width": "auto",
"height": getMinOfArray(imgList) + "px",
"display": "block",
"margin": "0 auto"
});
}
// TODO:
Check for the mode of the array and if imgHeight is less, adjust accordingly as well
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment