您的位置:首页 > Web前端 > JQuery

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

2008-05-07 13:15 337 查看
具体思路:

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

/* 自动缩略一些大图的小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());
}
});
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: