jquery圖片自動縮放

jquery.fn.ImageAutoSize = function(width,height)
{
    $("img",this).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());
        }
    });
}

調用:先引用上面的腳本或將上頁的腳本放入本身的JS庫,而後只要再加jquery

$(function(){ $("圖片組所在的容器").ImageAutoSize(限制最大寬,限制最大高);});this

相關文章
相關標籤/搜索