第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

我用Jquery的deferred對(duì)象為什么實(shí)現(xiàn)不了異步編程?

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title>小球運(yùn)動(dòng)+遞歸函數(shù)</title>

<style type="text/css">

.ball{

width: 40px;

height: 40px;

border-radius: 50%;

margin-top: 10px;

}

#ball1{

? ? ?background: red;

}

#ball2{

? ? ?background: yellow;

}

#ball3{

? ? ?background: blue;

}

</style>

</head>

<body>

<div class="ball" id = "ball1" ?style="margin-left:10px"></div>

<div class="ball" id = "ball2" ?style="margin-left:10px"></div>

<div class="ball" id = "ball3" ?style="margin-left:10px"></div>



<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>

<script type="text/javascript">

window.requestAnimFrame = (function() {

return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||

function(element) {

return window.setTimeout(callback, 1000 / 60);

};

})();

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

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

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


?

function animate (ball,distance) {

? var dtd = $.Deferred();

?requestAnimFrame(function(){

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

if(marginleft === distance){

dtd.resolve();

}else if(marginleft < distance){

marginleft++; ?? ?

}else{

marginleft--;

}

ball.style.marginLeft = marginleft + 'px';

animate(ball,distance);

});

? ?return dtd;

}

? ? ? ?

? ? ? ?animate(ball1,100).then(function(){

? ? ? ? return animate(ball2,200);

? ? ? ?}).then(function(){

? ? ? ? return animate(ball3,300);

? ? ? ?}).then(function(){

? ? ? ? return animate(ball3,150);

? ? ? ?}).then(function(){

? ? ? ? return animate(ball2,150);

? ? ? ?}).then(function(){

? ? ? ? return animate(ball1,150);

? ? ? ?})

</script>


</body>

</html>


正在回答

1 回答

后來自己搗弄出來了,下面是實(shí)現(xiàn)代碼:

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title>小球運(yùn)動(dòng)+clearInterval()</title>

<style type="text/css">

.ball{

width: 40px;

height: 40px;

border-radius: 50%;

margin-top: 10px;

}

#ball1{

? ? ?background: red;

}

#ball2{

? ? ?background: yellow;

}

#ball3{

? ? ?background: blue;

}

</style>

</head>

<body>

<div class="ball" id = "ball1" ?style="margin-left:10px"></div>

<div class="ball" id = "ball2" ?style="margin-left:10px"></div>

<div class="ball" id = "ball3" ?style="margin-left:10px"></div>



<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>

<script type="text/javascript">


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

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

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


?

function animate (ball,distance) {

?var timer = null;

?var dtd = $.Deferred();

?timer = setInterval(function(){

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

if(marginleft === distance){

clearInterval(timer);

dtd.resolve();

}else if(marginleft < distance){

marginleft++; ?? ?

}else{

marginleft--;

}

ball.style.marginLeft = marginleft + 'px';

},13);

? ?return dtd;

}

? ? ? ?animate(ball1,100).then(function(){

? ? ? ? return animate(ball2,200);

? ? ? ?}).then(function(){

? ? ? ? return animate(ball3,300);

? ? ? ?}).then(function(){

? ? ? ? return animate(ball3,150);

? ? ? ?}).then(function(){

? ? ? ? return animate(ball2,150);

? ? ? ?}).then(function(){

? ? ? ? return animate(ball1,150);

? ? ? ?})

</script>

</body>

</html>


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
進(jìn)擊Node.js基礎(chǔ)(二)
  • 參與學(xué)習(xí)       76727    人
  • 解答問題       242    個(gè)

本教程帶你攻破 Nodejs,讓 JavaScript流暢運(yùn)行在服務(wù)器端

進(jìn)入課程

我用Jquery的deferred對(duì)象為什么實(shí)現(xiàn)不了異步編程?

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)