[转载]jQuery实现动态改变图片的大小 | 香独秀

更新:2018年06月30日 17:02 前端 阅读(0)
标签: @jQuery #作者: 香独秀
jQuery实现动态改变图片的大小

jQuery实现动态改变图片的大小,具体代码如下:

-代码视图 
jQuery(window).load(function () {  
jQuery("#div_id img").each(function () {  
DrawImage(this, 500, 1000);
});  
});  
function DrawImage(ImgD, FitWidth, FitHeight) {  
var image = new Image();  
image.src = ImgD.src;  
if (image.width > 0 && image.height > 0) {  
if (image.width / image.height >= FitWidth / FitHeight) {  
if (image.width > FitWidth) {  
ImgD.width = FitWidth;  
ImgD.height = (image.height * FitWidth) / image.width;  
} else {  
ImgD.width = image.width;  
ImgD.height = image.height;  
}  
} else {  
if (image.height > FitHeight) {  
ImgD.height = FitHeight;  
ImgD.width = (image.width * FitHeight) / image.height;  
} else {  
ImgD.width = image.width;  
ImgD.height = image.height;  
}  
}  
}  
} 

当然是用jQuery的前提条件是要先引入jQuery核心包(稍微啰嗦一句)


感谢阅读本文,若本文对你有所帮助,不妨将其推荐给好友,与好友一起分享。
文章仅做学习交流使用,若您认为文章存在侵权或不合法行为等,请及时联系我们。
文章之版权归其合法拥者所有。转载原创内容无需联系本站站长,请注明原文出处及链接。
#原文:[IT技术网] https://www.173it.cn/plus/view.php?aid=8206
更新:2018年06月30日 17:02 前端 阅读(0)
标签: @jQuery #作者: 香独秀

阅读延伸

[转载]jQuery实现动态改变图片的大小 | 香独秀

jQuery实现动态改变图片的大小
标签: @jQuery 前端 香独秀 05月02日 21:08 继续阅读