js实现兼容IE、Firefox的图片缩放代码
js实现兼容IE、Firefox的图片缩放代码
发布时间:2016-12-30 来源:查字典编辑
摘要:本文实例讲述了js实现兼容IE、Firefox的图片缩放代码。分享给大家供大家参考,具体如下:functionSetSize(obj,wid...

本文实例讲述了js实现兼容IE、Firefox的图片缩放代码。分享给大家供大家参考,具体如下:

function SetSize(obj, width, height) { myImage = new Image(); myImage.src = obj.src; if (myImage.width > 0 && myImage.height > 0) { var rate = 1; if (myImage.width > width || myImage.height > height) { if (width / myImage.width < height / myImage.height) { rate = width / myImage.width; } else { rate = height / myImage.height; } } if (window.navigator.appName == "Microsoft Internet Explorer") { obj.style.zoom = rate; } else { obj.width = myImage.width * rate; obj.height = myImage.height * rate; } } }

用法:

复制代码 代码如下:<img src="img/offer/41936519.jpg" border="0" onload="SetSize(this, 80, 60)"/>

这种方法在IE、FIREFOX、OPERA、NETSCAPE测试都适用。

希望本文所述对大家JavaScript程序设计有所帮助。

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类