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

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

為什么marginLeft不能寫(xiě)在head下的style里面?

http://img1.sycdn.imooc.com//5837ee6d0001495b10320709.jpg

<!DOCTYPE?html>
<html>
<head>
	<title>Promise?animation</title>
	<meta?charset="utf-8">
	<style?type="text/css">
		.ball{
			width:?40px;
			height:?40px;
			border-radius:?50%;
			margin-left:?0px;
		}
		.ball_01{
			background:?red;
		}
		.ball_02{
			background:?yellow;
		}
		.ball_03{
			background:?green;
		}
	</style>
</head>
<body>
	<div?class="ball?ball_01"?style="margin-left:?0"></div>
	<div?class="ball?ball_02"?style="margin-left:?0"></div>
	<div?class="ball?ball_03"?style="margin-left:?0"></div>
</body>
<script?type="text/javascript"?src="node_modules/bluebird/js/browser/bluebird.js"></script>
<script?type="text/javascript">
	window.onload=function?()?{
		var?ball_01=document.querySelector(".ball_01");
	????var?ball_02=document.querySelector(".ball_02");
	????var?ball_03=document.querySelector(".ball_03");

		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(ball_01,100,function(){
		//?	animate(ball_02,200,function(){
		//?		animate(ball_03,300,function(){
		//?			animate(ball_03,150,function(){
		//?				animate(ball_02,150,function(){
		//?					animate(ball_01,150,function(){
		//?						//?
		//?					})
		//?				})
		//?			})
		//?		})
		//?	})
		//?})


		var?Promise?=?window.Promise;
		function?promiseAnmiate(ball,distance){
			return?new?Promise(function(resolve,reject){
				function?_animate()?{
					setTimeout(function(){
						var?marginLeft?=?parseInt(ball.style.marginLeft,10);
						if(marginLeft?===?distance){
							resolve();
						}else{
							if(marginLeft<distance){
								marginLeft++;
							}else{
								marginLeft--;
							}
							ball.style.marginLeft?=?marginLeft?+?"px";
							_animate();
						}
					},?13);
				}
				_animate();
			});
		}

		promiseAnmiate(ball_01,100)
		.then(function(){
			return?promiseAnmiate(ball_02,200)
		})
		.then(function(){
			return?promiseAnmiate(ball_03,300)
		})
		.then(function(){
			return?promiseAnmiate(ball_03,150)
		})
		.then(function(){
			return?promiseAnmiate(ball_02,150)
		})
		.then(function(){
			return?promiseAnmiate(ball_01,150)
		})
	}
</script>
</html>


正在回答

2 回答

ball.style.marginLeft 拿到的是行內(nèi)樣式! style 只是你獲取的這個(gè) DOM節(jié)點(diǎn) 的一個(gè)屬性而已(如果這個(gè)DOM節(jié)點(diǎn) 有 style 這個(gè)屬性的話) 靜下心來(lái)多鞏固下基礎(chǔ)吧。

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

精慕門(mén)8897441

并不是你說(shuō)的,.style.marginLeft是可以修改外部寫(xiě)的樣式的,你可以單獨(dú)寫(xiě)一個(gè)函數(shù)試試,只修改margionLeft的值,但是在這個(gè)例子里不行,不知道怎么回事。
2016-12-20 回復(fù) 有任何疑惑可以回復(fù)我~
#2

hey自然

哥~看下dom相關(guān)的知識(shí)再過(guò)來(lái)說(shuō)不是我說(shuō)的這個(gè)樣子
2016-12-20 回復(fù) 有任何疑惑可以回復(fù)我~

如果去掉div下的style,就不能運(yùn)行,為什么會(huì)出現(xiàn)這種問(wèn)題

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

舉報(bào)

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

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

進(jìn)入課程

為什么marginLeft不能寫(xiě)在head下的style里面?

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

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

幫助反饋 APP下載

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

公眾號(hào)

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