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

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

請問這個(gè)BUG是什么情況?http://idcbgp.cn/video/2879

<!DOCTYPE?html>
<html>

	<head>
		<meta?charset="UTF-8">
		<title></title>
		<style?type="text/css">
			*?{
				margin:?0;
				padding:?0;
			}
			
			#divs?{
				height:?260px;
				width:?160px;
				background-color:?antiquewhite;
				border-radius:?10px;
				position:?relative;
				left:?-160px;
			}
			
			#spans?{
				height:?100px;
				width:?20px;
				background-color:?cornflowerblue;
				border-radius:?5px;
				position:?absolute;
				left:?160px;
				margin-left:?1px;
				box-shadow:?5px?2px?10px?cornflowerblue;
				border:?1px?solid?white;
			}
			
			#div_opacity?{
				height:?100px;
				width:?100px;
				background-color:?brown;
				border-radius:?100px;
				box-shadow:?5px?2px?10px?#A52A2A;
				border:?1px?solid?white;
				opacity:?0.1;
			}
		</style>
		<script?type="text/javascript">
			window.onload?=?function()?{
				var?div?=?document.getElementById("divs"),
					span?=?document.getElementById("spans"),
					div_o?=?document.getElementById("div_opacity");
				var?speed?=?5;
				div.onmouseover?=?function()?{
					star_1(speed,?div,?0);
				}
				div.onmouseleave?=?function()?{
					star_1(speed,?div,?-160);
				}
			}
			var?timer?=?null;

			function?star_1(speed,?div,?itarget)?{
				clearInterval(timer);
				timer?=?setInterval(function()?{
					if?(div.offsetLeft?==?itarget)?{
						clearInterval(timer);
					}?else?{
						if?(itarget?==?0)?{
							speed?=?speed;
						}?else?if?(itarget<0)?{
							speed?=?-speed;
						}
						if?(div.offsetLeft?>?-160?/?2)?{
							speed?=?speed?*?3;
						}?else?{
							speed?=?speed;
						}
						div.style.left?=?div.offsetLeft?+?speed?+?"px";
						//解決抖動
						if?(div.offsetLeft?>?0)?{
							clearInterval(timer);
							div.style.left?=?"0px";
						}
						if?(div.offsetLeft?<?-160)?{
							clearInterval(timer);
							div.style.left?=?"-160px";
						}
					}
				},?50)
			}
		</script>
	</head>

	<body>
		<div?id="divs"><span?id="spans">分享</span></div>
		<div?id="div_opacity"></div>
	</body>

</html>

在代碼的第68行,”speed=-speed“,當(dāng)onmouseleave事件觸發(fā),div就會不停彈跳。

如果是改成”speed=-5“就不會出錯(cuò),請問這是發(fā)生了啥?蟹蟹

正在回答

2 回答

問題出現(xiàn)當(dāng) 觸發(fā)onmouseleave 時(shí),傳入speed=5,而star_1 中的局部變量speed=5,由于itarget=-160<0,所以,speed=-speed,即此時(shí)局部變量speed=-5,而下一個(gè)50ms,由于itarget=-160<0不變,繼續(xù)執(zhí)行speed=-speed,即此時(shí)局部變量speed=5了,到此發(fā)現(xiàn)問題了,在定時(shí)器的作用下,speed會在5與-5之間來回變動,有沒有達(dá)到任何 你設(shè)置的 停止條件,就出現(xiàn)了 無限制的抖動。而如果speed=-5,固定值 就不會出現(xiàn) 負(fù)負(fù)得正的情況了

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

飛天意大利面神獸 提問者

非常感謝!
2016-07-02 回復(fù) 有任何疑惑可以回復(fù)我~

speed=-speed這么寫容易亂,你的目的大概是簡單的變換一下符號,第一次進(jìn)這個(gè)語句speed由5變?yōu)?5,下面*3之后變?yōu)?15,當(dāng)?shù)诙螆?zhí)行這個(gè)語句的時(shí)候speed就會由-15變?yōu)?5,這樣問題就出來了。建議你傳參數(shù)的時(shí)候參數(shù)名和局部變量名不要相同。

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

飛天意大利面神獸 提問者

灰常感謝!
2016-07-02 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

請問這個(gè)BUG是什么情況?http://idcbgp.cn/video/2879

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

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

幫助反饋 APP下載

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

公眾號

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