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

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

請問為什么我實現(xiàn)的效果是這樣的?

<!DOCTYPE?html>
<html>
<head>
	<title></title>
	<style?type="text/css">
	*{
		padding:?0;
		margin:?0;
	}
	.a{
		width:?100px;
		height:?100px;
		background:?aquamarine;
		margin-bottom:?10px;
	}

	</style>
	<script?type="text/javascript">
		var?timer;
		window.onload=function(){
			var?div1=document.getElementById("div1");
			var?div2=document.getElementById("div2");
			
			div1.onmouseover=function(){
				startMove(this,"height",300);

			}
			div1.onmouseout=function(){
				startMove(this,"height",100);console.log("hello");
			}

			
		}
		function?startMove(obj,attr,iTarget){
				
				clearInterval(timer);
				var?icur=parseInt(getStyle(obj,attr));
				timer=setInterval(function(){
				speed=(iTarget-icur)/5;
				speed=speed>0?Math.ceil(speed):Math.floor(speed);
				if(icur==iTarget){
					
					clearInterval(timer);
				}
				else{	
						
					obj.style[attr]=icur+speed+'px';console.log("hello");

				}
},50);
			}
		function?getStyle(obj,attr){
			
			if(obj.currentStyle){
				return?obj.currentStyle[attr];
			}
			else{
				return?getComputedStyle(obj,false)[attr];
			}
		}
	</script>
</head>
<body>
	<div?id="div1"?class="a"></div>
	<div?id="div2"?class="a"></div>

</body>
</html>


正在回答

1 回答

????????var?timer;
????????window.onload?=?function(){
????????????var?div1?=?document.getElementById("div1");
????????????var?div2?=?document.getElementById("div2");
????????????div1.onmouseover?=?function(){
????????????????startMove(this,"height",300);
????????????}
????????????div1.onmouseout?=?function(){
????????????????startMove(this,"height",100);
????????????}
????????}
????????function?startMove(obj,attr,iTarget){
????????????clearInterval(timer);
????????????timer?=?setInterval(function(){
????????????????var?icur?=?parseInt(getStyle(obj,attr));
????????????????var?speed?=?(iTarget?-?icur)?/?5;
????????????????speed?=?speed?>?0???Math.ceil(speed)?:?Math.floor(speed);
????????????????if(icur==iTarget){
????????????????????clearInterval(timer);
????????????????}
????????????????else{
????????????????????obj.style[attr]?=?icur?+?speed?+?'px';
????????????????}
????????????},50);
????????}
????????function?getStyle(obj,attr){
????????????if(obj.currentStyle){
????????????????return?obj.currentStyle[attr];
????????????}
????????????else{
????????????????return?getComputedStyle(obj,false)[attr];
????????????}
????????}

?var icur = parseInt(getStyle(obj,attr)); 這句寫在setInterval 里面 否則定時器不能每次獲得新的屬性值

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

ZXJ03 提問者

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

舉報

0/150
提交
取消

請問為什么我實現(xiàn)的效果是這樣的?

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

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

幫助反饋 APP下載

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

公眾號

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