<div class="red" style="margin-left: 1px;"></div>
<div class="blue" style="margin-left: 1px;"></div>
<div class="green" style="margin-left: 1px;"></div>
<script type="text/javascript">
var b1=document.querySelector(".red");
var b2=document.querySelector(".blue");
var b3=document.querySelector(".green");
var Promise=window.Promise;
console.log(Promise)
function promiseMove(ball,distance){
return new Promise(function(resolve,reject){
function _move(){
var mleft=parseInt(ball.style.marginLeft,10);
setTimeout(function(){
var mleft=parseInt(ball.style.marginLeft,10);
if(mleft===distance){
resolve()
}else{
mleft<distance?mleft++:mleft--
}
ball.style.marginLeft=mleft+'px';
_move();
},13)
};
_move();
})
}
promiseMove(b1,100)
.then(function(){
return promiseMove(b2,200)
}).then(function(){
return promiseMove(b3,300)
}).then(function(){
return promiseMove(b3,150)
}).then(function(){
return promiseMove(b2,150)
}).then(function(){
return promiseMove(b1,150)
})
</script>