您的位置:首页 > Web前端 > JavaScript

js 鼠标滚轮缩放图片

2010-08-04 14:48 281 查看
<html>
<script type="text/javascript">
function resizeimg(ImgD,iwidth,iheight) {
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
    ImgD.style.cursor= "pointer"; //改变鼠标指针
   if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判断浏览器,如果是IE
     ImgD.title = "请使用鼠标滚轮缩放图片";
     ImgD.onmousewheel = function img_zoom() //滚轮缩放
    {
         var zoom = parseInt(this.style.zoom, 10) || 100;
         zoom += event.wheelDelta / 12;
         if (zoom> 0) this.style.zoom = zoom + "%";
         return false;
    }
  }
}
}
</script>
<body>
示例:
<img alt="" src="部门ID对照表.jpg" onload="resizeimg(this,this.width,this.height);" />
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: