<div id="box"></div> <script type="text/javascript"> var oBox=document.getElementById("box"); goudan(oBox,"left",500,10); function goudan(obj, attr, taregt,speed){ var starVal=parseInt(getStyle(obj,attr)); var timer=setInterval(function(){ setInterval +=speed; if(setInterval>=taregt){ starVal=taregt clearInterval(timer); } obj.style[attr]=starVal+"px"; },13); function getStyle(obj,attr){ return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj)[attr];} }; </script>
2 回答
已采纳
stone310
TA贡献361条经验 获得超191个赞
两个变量名称写错..
var timer=setInterval(function(){ setInterval +=speed; //这里是starVal+=speed; if(setInterval>=taregt){ //这里是starVal>=taregt; starVal=taregt clearInterval(timer); }
添加回答
举报
0/150
提交
取消