首页 > 编程语言 > 详细

图片javascript缩小

时间:2016-07-15 09:33:24      阅读:158      评论:0      收藏:0      [点我收藏+]
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" style="zoom: 0.1" onload="SetSize(this, 80, 60)"/>

  

图片javascript缩小

原文:http://www.cnblogs.com/yjung/p/5672408.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!