永发信息网

关于javascript的settimeout函数的问题,我递归调用做动画,但是却瞬间到达!为什么!!!

答案:2  悬赏:80  手机版
解决时间 2021-01-04 00:29
  • 提问者网友:欲劫无渡
  • 2021-01-03 04:25
function moveElemet(tarElemet,position){<br><br> var count = parseInt(tarElemet.style.marginLeft);<br><br> if (count &lt; position){   // on the left, move right <br> count+=1;<br> alert(count);<br> tarElemet.style.marginLeft=count+&quot;px&quot;;<br> setTimeout ( moveElemet( tarElemet,position) ,1000);<br> }<br><br>就是把tarElemet往右移动,用settimeout的1000ms延迟做出动画效果,但是它却是瞬间把marginLeft值改变成position值了,是忽略了settimeout的delay属性吗?求高手指教!!!!!!!!!!
最佳答案
  • 五星知识达人网友:行路难
  • 2021-01-10 04:28
带参的方法不是那么调的<br>&lt;script&gt;<br>function moveElemet(tarElemet,position)<br>{<br> var count = parseInt(tarElemet.style.marginLeft);<br> if (count &lt; position){   // on the left, move right <br> count+=1;<br> alert(count);<br> tarElemet.style.marginLeft=count+&quot;px&quot;;<br> setTimeout (&quot;moveElemet(&quot;+tarElemet&quot;,&quot;+position+&quot;)&quot;,1000);<br>}<br>&lt;/script&gt;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯