亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

不知道錯在哪了??

<!doctype?html>
<html>
	<head>
		<meta?charset="utf-8">
		<title>hello?world</title>
		<style?type="text/css">
			#li1{
				width:200px;
				height:100px;
				list-style:none;
				background-color:yellow;
				border:3px?solid?#000;
				opacity:0.3;
				filter:alpha(opacity:30);
			}?
		</style>
		<script?src="move.js"></script>
		<script?type="text/javascript">
			window.onload=function(){
				var?li=document.getElementById("li1");
				li.onmouseover=function(){
					startMove(li,{width:400,height:200});
				};
			};
		</script>
	</head>
	<body>
		<ul>
			<li?id="li1"></li>
		</ul>
	</body>
</html>

下面是js

function?startMove(obj,json,fn){
	clearInterval(obj.timer);
	obj.timer=setInterval(function(){
		for(var?attr?in?json){
			var?temp=0;
			//取當前值
			if(attr=="opacity"){
				temp=Math.round(parseFloat(getStyle(obj,attr))*100);
			}else{
				temp=parseInt(getStyle(obj,attr));
			}
			//計算速度
			var?speed=(json[attr]-temp)/8;
			speed=speed>0?Math.ceil(speed):Math.floor(speed);
			//檢測停止
			if(temp==json[attr]){
				clearInterval(obj.timer);
				if(fn){
					fn();
				}
			}else{
				if(attr=="opacity"){
					obj.style.filter="alpha(opacity:"+(temp+speed)+")";
					obj.style.opacity=(temp+speed)/100;
				}else{
					obj.style[attr]=temp+speed+"px";
				}
			}
		}
	},30);
}

function?getStyle(obj,attr){
	if(obj.currentStyle){
		return?obj.currentStyle[attr];
	}else{
		return?getComputedStyle(obj,false)[attr];
	}
}

為什么沒反應呢??

正在回答

1 回答

測試了一下可以用,看看是不是JS<script?src="move.js"></script>引用路徑有誤,另外需要加Flag來保證只有每個值都達到target才停止動畫,不然透明度到1寬度還沒到400就不動了

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

不知道錯在哪了??

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號