亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

從第二個小球開始,速度依次變快是什么情況?

<!-- callback.html -->

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<style type="text/css">

.ball{

height: 100px;

width: 100px;

border-radius: 50%;

margin-left: 0;

}

.ball1{

background: red;

}

.ball2{

background: yellow;

}

.ball3{

background: blue;

}

</style>

</head>

<body>

<div class="ball ball1" style="margin-left: 0px"></div>

<div class="ball ball2" style="margin-left: 0px"></div>

<div class="ball ball3" style="margin-left: 0px"></div>

<script type="text/javascript">

// var ball=document.getElementsByClassName("ball");

// var ball1=ball[0];

// var ball2=ball[1];

// var ball3=ball[2];

var ball1=document.querySelector(".ball1");

var ball2=document.querySelector(".ball2");

var ball3=document.querySelector(".ball3");

function animate(ball,distance,callback) {

setTimeout(function(){

var marginLeft=parseInt(ball.style.marginLeft, 10);

if (marginLeft===distance) {

callback&&callback();

}else if(marginLeft<distance){

marginLeft++;

}else{marginLeft--};

ball.style.marginLeft=marginLeft+"px";

animate(ball, distance, callback);



},13)

}

animate(ball1,400,function(){

animate(ball2,400,function(){

animate(ball3,400,function(){

animate(ball1,100,function(){

animate(ball2,200,function(){

animate(ball3,300,function(){

//

})

})

})

})

})

})

</script>

</body>

</html>


正在回答

2 回答

啊……幫你看了之后發現你自己解決了……不過我沒太懂你這句“不然setTimeout會疊加的”是什么意思。麻煩您再細致講一下可以不

0 回復 有任何疑惑可以回復我~

原來遞歸停止的條件是在第一個else里面,只要marginLeft相等了,就會停止遞歸了,不然setTimeout會疊加的。

0 回復 有任何疑惑可以回復我~
#1

weibo_煙夢江南_03879528

不return嗎?不return會一直遞歸
2017-07-04 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
進擊Node.js基礎(二)
  • 參與學習       76735    人
  • 解答問題       242    個

本教程帶你攻破 Nodejs,讓 JavaScript流暢運行在服務器端

進入課程

從第二個小球開始,速度依次變快是什么情況?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號