• 鼠标滚动缩放图片效果


     前段时间本人在做项目时,做了一个鼠标滚动缩放图片效果,图片支持多个,多个图片循环缩放,花了点时间整理了下,把它贴出来,与大家分享下,在ie6.0,ie7.0,firefox都测试过,没有问题。

    <html>

    <head>
    <title>鼠标滚动图片缩放</title>
    <script language="javascript">
          if (window.addEventListener)
          {
             window.addEventListener('DOMMouseScroll', wheel, false);//给firefox添加鼠标滚动事件
          }
          
          function wheel(event)
          {
             return wheelimg(event);
          }
          function bbimg()
          {
             var div = document.getElementById("div1");
             var allImg = div.getElementsByTagName("IMG");
             for(i=0;i<allImg.length;i++)
                 {
                   var zoom=parseInt(allImg[i].style.zoom, 10)||100;
                   zoom+=event.wheelDelta/12;
                   if (zoom>0) allImg[i].style.zoom=zoom+'%';
                 }
           }
            
           function wheelimg(event)
           {
            var delta = 0;
            var div = document.getElementById("div1");
            if (event.detail)
            {
                //如果是firefox
                var allImg = div.getElementsByTagName("IMG");
                var isThis=false;//现判断鼠标中仑的元素是不是包含在那个div里面
                for(i=0;i<allImg.length;i++)
                 {
                       isThis=true;
                       allImg[i].width=allImg[i].width+event.detail*12;
                    event.returnValue = false;
                 }
                 
             }
              return true;
            }
        </script>
    </head>
    <body  onmousewheel="bbimg()">
        <form id="form1" runat="server">
            <div id="div1">
             <img id="wheelimg" src="http://farm3.static.flickr.com/2782/4098845549_fe43958798.jpg" style="cursor: pointer;" border="0" />
             <img id="wheelimg1" src="http://farm3.static.flickr.com/2448/4099603568_69b7811d55.jpg" style="cursor: pointer;" border="0" />
            </div>
        </form>
    </body>
    </html>
  • 相关阅读:
    变量定义和声明的差别(整理)
    堆栈指针理解
    HDU 4349 Xiao Ming&#39;s Hope
    iOS 8中CLLocationManager及MKMapView showUserLocation失败的解决的方法
    Ant命令行操作
    linux awk命令详细使用方法
    mysql 修改[取消]timestamp的自动更新
    cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第六步---炮台&amp;点击炮台加入英雄&amp;英雄升级
    SendMessage、PostMessage原理
    poj 2104 K-th Number 主席树+超级详细解释
  • 原文地址:https://www.cnblogs.com/yeer/p/1418444.html
Copyright © 2020-2023  润新知