Skip to content

Instantly share code, notes, and snippets.

@vyspiansky
Last active March 1, 2021 15:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vyspiansky/8870384 to your computer and use it in GitHub Desktop.
Save vyspiansky/8870384 to your computer and use it in GitHub Desktop.
jQuery: fixed image resize
/*
* Source: http://snipplr.com/view/62552/mage-resize/
*/
$(window).bind("load", function() {
// IMAGE RESIZE
$('#product_cat_list img').each(function() {
var maxWidth = 120;
var maxHeight = 120;
var ratio = 0;
var width = $(this).width();
var height = $(this).height();
if(width > maxWidth){
ratio = maxWidth / width;
$(this).css("width", maxWidth);
$(this).css("height", height * ratio);
height = height * ratio;
}
var width = $(this).width();
var height = $(this).height();
if(height > maxHeight){
ratio = maxHeight / height;
$(this).css("height", maxHeight);
$(this).css("width", width * ratio);
width = width * ratio;
}
});
//$("#contentpage img").show();
// IMAGE RESIZE
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment