使用jQuery自动缩图片 (转载)

具体思路:
  1. 通过具体容器取得容器内所有图片
  2. 循环检查所有图片长宽
  3. 对超过的图重新定高度.
直接写成一个扩展好了,以后可以直接用.

/* 自动缩略一些大图的小JS
    吕 lvjiyong@Gmail.com
    http://www.lvjiyong.com/tag/jquery/
    更新:2007.9.22
*/
jQuery.fn.ImageAutoSize = function(width,height)
{
    $("div.info_view img").each(function()
    {
        var image = $(this);
        if(image.width()>width)
        {
            image.width(width);
            image.height(width/image.width()*image.height());
        }
        if(image.height()>height)
        {
            image.height(height);
            image.width(height/image.height()*image.width());
        }
    });
}

原文地址:https://www.cnblogs.com/luluping/p/1186705.html