js实现兼容IE、Firefox的图片缩放代码
本文实例讲述了js实现兼容IE、Firefox的图片缩放代码。分享给大家供大家参考,具体如下:
functionSetSize(obj,width,height){
myImage=newImage();
myImage.src=obj.src;
if(myImage.width>0&&myImage.height>0){
varrate=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=="MicrosoftInternetExplorer"){
obj.style.zoom=rate;
}else{
obj.width=myImage.width*rate;
obj.height=myImage.height*rate;
}
}
}
用法:
<imgsrc="img/offer/41936519.jpg"border="0"style="zoom:0.1"onload="SetSize(this,80,60)"/>
这种方法在IE、FIREFOX、OPERA、NETSCAPE测试都适用。
希望本文所述对大家JavaScript程序设计有所帮助。
热门推荐
10 外婆祝福语短句唯美简短
11 送弟弟中秋祝福语简短
12 接亲新郎进门祝福语简短
13 娘家妈妈新婚祝福语简短
14 喜事作文结尾祝福语简短
15 婚礼明星的祝福语简短
16 除夕对同学简短祝福语
17 立秋对母亲祝福语简短
18 结婚对白誓言简短祝福语