最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

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

我用DOM2級(jí)綁定多個(gè)事件,為什么要把定時(shí)器取消才能執(zhí)行?

<!DOCTYPE?html>
<html>
<head>
<meta?charset="UTF-8">
<title>鏈?zhǔn)絼?dòng)畫</title>
<style?type="text/css">
*{margin:0;padding:0;}
ul,li{
list-style:none;
}
ul?li{
width:200px;
height:100px;
background:yellow;
margin-bottom:20px;
border:4px?solid?#000;
filter:alpha(opacity=30);
opacity:0.3;
}
</style>
<script?src="move.js"></script>

</head>
<body>
<ul>
<li?id="li1"></li>
</ul>
<script?type="text/javascript">

var?Li=document.getElementById('li1');
Li.addEventListener('mouseover',function(){startMove(Li,'width',400);},false);

Li.addEventListener('mouseover',function(){startMove(Li,'height',200);},false);

Li.addEventListener('mouseover',function(){startMove(Li,'opacity',100);},false);

</script>
</body>
</html>

接下來(lái)是引入的js部分

function?getStyle(obj,attr){//傳入兩個(gè)參數(shù):對(duì)象和屬性
	if?(obj.currentStyle)?{??//currentStyle針對(duì)ie瀏覽器
		return?obj.currentStyle[attr];
	}?else?{???//getComputerStyle針對(duì)firefox瀏覽器
		return?getComputedStyle(obj,false)[attr];
	}
}
//?var?timer=null;
function?startMove(obj,attr,iTarget,fn){
	//?clearInterval(obj.timer);
	obj.timer=setInterval(function(){
		//1、取當(dāng)前的值
		var?icur=0;
		if?(attr=='opacity')?{
			icur=Math.round(parseFloat(getStyle(obj,attr))*100);
			//*100是為了和17行代碼中的透明度對(duì)應(yīng)
		}?else?{
			icur=parseInt(getStyle(obj,attr));
		}
		//2、計(jì)算速度
		var?speed=(iTarget-icur)/8;
		speed=speed>0?Math.ceil(speed):Math.floor(speed);
		//3、檢測(cè)停止
		if?(icur==iTarget)?{
			clearInterval(obj.timer);
			if?(fn)?{
				fn();
			}
		}?else?{
			if?(attr=='opacity')?{
				obj.style.filter='alpha(opacity='+(icur+speed)+')';//針對(duì)ie瀏覽器
				obj.style.opacity=(icur+speed)/100;//針對(duì)firefox和chrome瀏覽器的
			}?else?{
			//?obj.style.width=icur+speed+'px';
			obj.style[attr]=icur+speed+'px';
			}
		}
	},30)
}


正在回答

2 回答

分別給li添加mouseover事件后,后一個(gè)li里面的startMove()里面的clearInterval()會(huì)清除上一個(gè)li的startMove()函數(shù)里的定時(shí)器,所以就只有最后一個(gè)有效果了

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

關(guān)于js部分第10行,清楚定時(shí)器,為什么要注釋掉才有效果,如果不注釋掉,只有透明度的變化,想不明白

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

舉報(bào)

0/150
提交
取消

我用DOM2級(jí)綁定多個(gè)事件,為什么要把定時(shí)器取消才能執(zhí)行?

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

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

幫助反饋 APP下載

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

公眾號(hào)

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