图片大小随鼠标滚动而改变的兼容IE和firefox的代码

搞了半天,终于搞定,但是在firefox下面显示效果不是很好,代码如下:(后面附上注明几点)

 1 None.gif < html >
 2 None.gif < head >
 3 None.gif     < title > 无标题页 </ title >
 4 ExpandedBlockStart.gifContractedBlock.gif     < script  language ="javascript" > dot.gif
 5InBlock.gif      if (window.addEventListener)
 6ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif{
 7InBlock.gif         window.addEventListener('DOMMouseScroll', wheel, false);//给firefox添加鼠标滚动事件
 8ExpandedSubBlockEnd.gif      }

 9InBlock.gif      //else
10InBlock.gif      //{
11InBlock.gif        // window.onmousewheel = document.onmousewheel = wheel;//ie
12InBlock.gif      //}
13InBlock.gif      
14InBlock.gif      function wheel(event)
15ExpandedSubBlockStart.gifContractedSubBlock.gif      dot.gif{
16InBlock.gif         var delta = 0;
17InBlock.gif         var div = document.getElementById("div1");
18ExpandedSubBlockStart.gifContractedSubBlock.gif         if (!event) /**//* For IE. */
19ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif{
20InBlock.gif            event = window.event;
21ExpandedSubBlockEnd.gif         }

22InBlock.gif         if (event.wheelDelta)
23ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif
24InBlock.gif            //让一个是IE
25InBlock.gif            //if(event.srcElement.tagName=="IMG" && div.contains(event.srcElement))
26InBlock.gif            //{
27InBlock.gif               //event.srcElement.width+=event.wheelDelta/15;
28InBlock.gif              // return false;
29InBlock.gif            //}
30ExpandedSubBlockEnd.gif         }
 
31InBlock.gif         else if (event.detail) 
32ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif
33InBlock.gif            //如果是firefox
34InBlock.gif            var allImg = div.getElementsByTagName("IMG");
35InBlock.gif            var isThis=false;//现判断鼠标中仑的元素是不是包含在那个div里面
36InBlock.gif            for(i=0;i<allImg.length;i++)
37ExpandedSubBlockStart.gifContractedSubBlock.gif             dot.gif{
38InBlock.gif                if(allImg[i]==event.target)
39ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
40InBlock.gif                   isThis=true;
41ExpandedSubBlockEnd.gif                }

42ExpandedSubBlockEnd.gif             }

43InBlock.gif             if(isThis && event.target.tagName=="IMG")
44ExpandedSubBlockStart.gifContractedSubBlock.gif             dot.gif{
45InBlock.gif                event.target.width=event.target.width+event.detail*12;
46InBlock.gif                event.returnValue = false;
47ExpandedSubBlockEnd.gif             }

48ExpandedSubBlockEnd.gif          }

49InBlock.gif          return true;
50ExpandedSubBlockEnd.gif        }

51InBlock.gif        function bbimg(o)
52ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
53InBlock.gif           var zoom=parseInt(o.style.zoom, 10)||100;
54InBlock.gif           zoom+=event.wheelDelta/12;
55InBlock.gif           if (zoom>0) o.style.zoom=zoom+'%';
56InBlock.gif           return false;
57ExpandedSubBlockEnd.gif        }

58ExpandedBlockEnd.gif    
</ script >
59 None.gif </ head >
60 None.gif < body >
61 None.gif     < form  id ="form1"  runat ="server" >
62 None.gif     < div >
63 None.gif         < div  id ="div1"
64 None.gif        <table class ="tablebody2"  style ="table-layout:fixed;"  border ="0"  width ="90%" >
65 None.gif            < tr >
66 None.gif                < td >
67 None.gif                   < img  id ="11"  src ="UserFolder/00.jpg"  onclick ="javascript:window.open(this.src);"  
68 None.gifstyle ="cursor: pointer;"  onload ="javascript:if(this.width>screen.width-500)this.style.width=screen.width-500;"  
69 None.gifonmousewheel ="return bbimg(this)"  border ="0"   />
70 None.gif                </ td >
71 None.gif            </ tr >
72 None.gif          </ table >
73 None.gif         </ div >
74 None.gif     </ form >
75 None.gif </ body >
76 None.gif </ html >
77 None.gif
78 None.gif


在上面的代码里,我首先把判断IE捕捉IE鼠标滚动事件的代码去掉了,因为如果不去掉效果和去掉以后直接写
onmousewheel="return bbimg(this)"的运行效果要相差很远;
还有一点就是方了个table,加上了style="table-layout:fixed;属性,如果不用table用div我找不到任何样式来控制当这个图片月滚越大的时候会把所有的页面样式都搞坏;

页面图片效果可以在 一诺操盘手网预览!

转载于:https://www.cnblogs.com/pwqzc/archive/2007/07/14/818302.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值