为了账号安全,请及时绑定邮箱和手机立即绑定

透明度变化问题,应该是鼠标移动变不透明,移开变0.3透明度,可是不知道哪的问题

透明度变化问题,应该是鼠标移动变不透明,移开变0.3透明度,可是不知道哪的问题

慕府戏子 2016-08-01 20:25:59
<!DOCTYPE html> <html> <head>     <meta charset="UTF-8">     <title></title>     <style>         *{margin: 0;             padding: 0;         }         ul{             list-style: none;position: fixed ;top: 20%;         }         ul li {             width:200px;             height: 100px;             background:#5a5a5a;             margin-bottom: 20px;             opacity:0.3;         }     </style>     <script>         window.onload = function()         {             var Li1=document.getElementById('id1');             var Li2=document.getElementById('id2');             Li2.onmousemove=function(){                 startMove(this,{'width':400,'opacity':100})             }             Li2.onmouseout=function(){                 startMove(this,{'width':200,'opacity':30})             }         }         //var timer= null;         function startMove(obj,json,fn)/*obj多个参数的定义*/         {             clearInterval(obj.timer);             var a=true;             obj.timer = setInterval(function(){                 for(var attr in json) {                     var icur=0;                     if(attr=='opacity'){                         icur=parseInt(getstyle(obj, attr))*100                     }else {icur=parseInt(getstyle(obj, attr))}                     var speed = (json[attr] - icur) / 3;                     speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);                     if (icur!= json[attr])                     {                         a=false;                         if(attr=='opacity'){                             obj.style['opacity']=(icur+speed)/100;                         }                         else {obj.style[attr] = icur + speed + 'px';}                     }                 }                 if(a){                     clearInterval(obj,timer);                     if(fn){fn();}                 }             },30)}         function getstyle(obj,attr){             if(obj.currentStyle){                return obj.currentStyle[attr]             }             else {                return getComputedStyle(obj,false)[attr]             }         }     </script> </head> <body> <ul>     <li id="id1">11</li>     <li id="id2">22</li>     <li id="id3"></li> </ul> </body> </html>
查看完整描述

5 回答

?
南风蛮

TA贡献9条经验 获得超8个赞

效果已经出来没错,如果是透明度没变化,opacity不支持ie8及以下,你可以替换成filter兼容

查看完整回答
反对 回复 2016-08-15
?
一杯2块的奶茶

TA贡献226条经验 获得超75个赞

他当前得到的透明度和宽度始终是0.3和200呀,数值上下波动后,到后面就不变了,感觉确实是有问题的,但是我也没解决,哎,研究了一会,看是看懂了,这个问题我之前也看到过,后面不了了之了,现在又看到了

查看完整回答
反对 回复 2016-08-02
?
ziom

TA贡献948条经验 获得超1109个赞

谢邀。不过我很长时间没接触js了,你找错了人。

查看完整回答
反对 回复 2016-08-01
?
刚毅87

TA贡献345条经验 获得超309个赞

没问题啊,效果还不错.

查看完整回答
反对 回复 2016-08-01
  • 慕府戏子
    慕府戏子
    你好,有的,我原先想法是鼠标移动上去的时候,变成不透明,移开后恢复初始透明度,但是现在移动上去后,透明度几乎没变,并没有变成不透明,现在初始的透明度是0.3,按理说,移动上去变1,移开后变回0.3.可是,现在效果做不出,不知道哪的问题。
  • 5 回答
  • 0 关注
  • 1518 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信