当前位置:编程学习 > JS >>

自动根据图片高度宽度缩放jquery代码

调用:先引用上面的脚本或将上页的脚本放入自己的js库,然后只要再加 $(function(){ $(”图片组所在的容器”).imageautosize(限制最大宽,限制最大高);});

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


}

补充:网页制作,jquery 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,