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

我的为什么不能实现链式运动..找半天bug了

我的为什么不能实现链式运动..找半天bug了

朕的江山啊 2017-03-27 15:32:56
<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title></title>        <style type="text/css">            div{                width:100px;                height:50px;                background:yellow;                margin:20px;                margin-bottom:none;            }        </style>    </head>    <script type="text/javascript">        window.onload = function(){            var list=document.getElementsByTagName("div");            for(var i=0 ; i<list.length ; i++){                list[i].tim=null;                list[i].onmouseover=function(){                    var g=this;                    change(this,"width",200,function(){                        change(g,"height",100);                    });                }                list[i].onmouseout=function(){                    change(this,"width",100);                }            }        }                function getAttr(obj,att){            if(obj.currentStyle){                return obj.currentStyle[att];            }else{                return getComputedStyle(obj,false)[att];            }        }                function change(obj,att,iTarget,fn){            var speed=null;            clearInterval(obj.tim);            obj.tim=setInterval(function(){                var geta=parseInt(getAttr(obj,att))                speed=(iTarget-geta)/20;                speed=speed>0?Math.ceil(speed):Math.floor(speed);                if(geta==iTarget){                    if(fn){                        fn();                    }                    clearInterval(obj.tim);                }else{                    obj.style[att]=geta+speed+"px";                }            },30)        }    </script>    <body>        <div id="d1">        </div>        <div id="">        </div>        <div id="">        </div>    </body></html>
查看完整描述

1 回答

添加回答

代码语言

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号