基于jquery的图片尺寸调整
resize.js
复制代码 代码如下:
$(window).bind(load, function() {
// image resize
$('#product_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
});
代码很简洁,使用起来也很简单,小伙伴们直接使用即可