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

求大神帮忙看一下,看了一下午就是不知道哪里出错了,求助!!!

<!DOCTYPE html>
<html>
<head>
    <title>透明度的getSyle方法的切换</title>
    <style type="text/css">
    *{margin: 0;padding: 0;}
        ul,li{list-style: none;}
        ul li{
            width: 200px;
            height: 200px;
            background: yellow;
            filter: alpha(opacity:30);
            opacity: 0.3;
            }
    </style>
    <script type="text/javascript">
        window.onload=function(){
            var ali=document.getElementsByTagName('li');

            ali.onmouseover=function(){
                Move(this,100,'opacity');
            }
            ali.onmouseout=function(){
                Move(this,30,'opacity');
            }
        }

        function Move(obj,iTarget,attr){
            clearInterval(obj.timer);
            obj.timer=setInterval(function(){
                var icur=0;
                if(attr=='opacity'){
                    icur=parseFloat(getStyle(obj,attr))*100;
                }else{
                    icur=parseInt(getStyle(obj,attr));
                }
                var speed=(iTarget-icur)/8;
                speed=speed>0?Math.ceil(speed):Math.floor(speed);
                if(icur==iTarget){
                    clearInterval(obj.timer);
                }else{
                    if(attr=='opacity'){
                        obj.style.filter='alpha(opacity:'+(icur+speed)+')';
                        obj.style.opacity=(icur+speed)/100;
                    }ele{
                        obj.style[attr]=icur+speed+'px';
                    }
                }
            },30);
        }
        function getStyle(obj,attr){
            if(obj.currentStyle){
                return obj.currentStyle[attr];
            }else{
                return getComputedStyle(obj,false)[attr];
            }
        }
    </script>
</head>
<body>
<ul>
    <li></li>
</ul>
</body>
</html>


正在回答

3 回答

1.45行的else拼写错了

2.第20行的ali应该是一个数组,应该写ali[0],或者通过for循环遍历。

1 回复 有任何疑惑可以回复我~
#1

qq_Mark单_0 提问者

非常感谢!
2016-09-17 回复 有任何疑惑可以回复我~

 if(attr=='opacity'){

                        obj.style.filter='alpha(opacity:'+(icur+speed)+')';

                        obj.style.opacity=(icur+speed)/100;

                    }ele{

                        obj.style[attr]=icur+speed+'px';

少两个else 少了个s

0 回复 有任何疑惑可以回复我~

(1)ele{

                        obj.style[attr]=icur+speed+'px';

                    }

else少了个s;

(2)getElementsByTagName('li')获取到的是li的数组,使用ali[0]调用函数才行

1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

求大神帮忙看一下,看了一下午就是不知道哪里出错了,求助!!!

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信