使用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());
}
});
}
通过具体容器取得容器内所有图片
循环检查所有图片长宽
对超过的图重新定高度.
直接写成一个扩展好了,以后可以直接用.
/* 自动缩略一些大图的小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());
}
});
}
相关文章推荐
- 使用JQuery的全屏背景图片,自动适应各种屏幕和浏览器
- [转贴]使用jQuery自动缩图片 - [jQuery]
- 使用jQuery自动缩图片
- 使用C#进行图片转换格式,缩放,自动旋转,保留exif(转载)
- 使用jQuery实现图片自动轮播
- 使用jQuery做简单的图片轮播效果
- Confluence 为图片,视频,音频和文档文件使用自动完成
- 使用java的html解析器jsoup和jQuery实现一个自动重复抓取任意网站页面指定元素的web应用
- Jquery图片轮播插件--jcarousellite的使用
- jQuery UI AutoComplete 自动完成使用小记
- [jQuery代码]如何使用javascript/jQuery预先加载图片
- 在浏览器中实现图片粘贴的jQuery插件-- pasteimg使用指南
- jquery实现图片左右间隔滚动特效(可自动播放)
- Auto Layout 使用心得(五)—— 根据文字、图片自动计算 UITableViewCell 高度
- 如何使用css自动使得图片自己改变大小
- 使用FileUpload控件上传图片并自动生成缩略图、自动生成带文字和图片的水印图
- JQuery使用一例:点击文本框(请输入关键字)时自动清空文本框中的预设信息
- 使用jquery完成定时弹出广告图片
- jQuery自动或手动图片切换效果
- jquery使用ColorBox弹出图片组浏览层实例演示