当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery在页面加载时动态修改图片尺寸的方法教程

jQuery在页面加载时动态修改图片尺寸的方法教程

2019年05月17日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jquery在页面加载时动态修改图片尺寸的方法。分享给大家供大家参考。具体如下:

$(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
});

希望本文所述对大家的jquery程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网