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

为什么我在学习 promise的时候 第二个小球就不会动了

为什么我在学习 promise的时候 第二个小球就不会动了

qq_画晚_0 2017-11-02 16:58:36
代码如下,只有第一个小球会动,然后就没然后了~~<script type="text/javascript">   var ball1 = document.querySelector('.ball1');   var ball2 = document.querySelector('.ball2');   var ball3 = document.querySelector('.ball3');   var Promise = window.Promise;   function p_animate(ball,distance){     return new Promise(function(resolve,reject){       function _animate(){         setTimeout(function(){           var marginLeft = ball.style.marginLeft==''?0:parseInt(ball.style.marginLeft);           if (marginLeft == distance) {             resolve;           }else{             if (marginLeft<distance) {               marginLeft++;             }else{               marginLeft--;             };             ball.style.marginLeft = marginLeft+'px';           }           _animate();         },13);       }       _animate()     })   }   p_animate(ball1,100)     .then(function(){       return p_animate(ball2,200)     })     .then(function(){       return p_animate(ball3,300)     })     .then(function(){       return p_animate(ball3,150)     })     .then(function(){       return p_animate(ball2,150)     })     .then(function(){       return p_animate(ball1,150)     }) </script>
查看完整描述

1 回答

?
牛奶老哥哥

TA贡献204条经验 获得超92个赞

resolve 是函数需要执行啊 

resolve();


查看完整回答
1 反对 回复 2017-11-02
  • 1 回答
  • 0 关注
  • 1122 浏览
慕课专栏
更多

添加回答

举报

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