改變透明度的代碼,代碼運(yùn)行沒(méi)反應(yīng)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無(wú)標(biāo)題文檔</title>
<style style="text/css">
*{padding:0;margin:0;}
div{width:150px;
margin-left:20px;
height:200px;
? ? background:green;
filter:alpha(opacity:30);
opacity:0.3;
float: left;}
</style>
<script type="text/javascript">
window.onload=function(){
var adiv= document.getElementsByTagName("div");
for (var i=0;i<adiv.length;i++) {
adiv[i].alpha=30;
adiv[i].onmoseover=function(){startMove(this,100);}
adiv[i].onmouseout=function(){startMove(this,30);}
}
}
function startMove(obj,iTarget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=0
if(obj.alpha>iTarget){
speed = -10;
}
else{
speed = 10;
}
if(obj.alpha == iTarget) {
clearInterval(obj.timer);
}
else{obj.alpha+=speed;
obj.style.filter="alpha(opacity:"+obj.alpha+")";
obj.style.opacity=obj.alpha/100;}
},30)
}
</script>
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html>
2017-03-09
老鐵,你寫掉了一個(gè)字母,鼠標(biāo)鼠標(biāo)事件根本不能執(zhí)行。
adiv[i].onmoseover=function(){startMove(this,100);}中 ? ?onmoseover應(yīng)該是onmouseover
2017-03-09
我一般是先在瀏覽器里面看,有沒(méi)有語(yǔ)法報(bào)錯(cuò)的,如果沒(méi)有報(bào)錯(cuò)但還是不能執(zhí)行,就要去找那些小問(wèn)題了,邏輯對(duì)不對(duì),拼寫這些最基本的,建議在寫的時(shí)候不要急,關(guān)鍵字寫對(duì),不用的代碼盡量先注釋,不要老去刪除,往往刪除的過(guò)程中很容易誤刪掉一些東西。說(shuō)了半天其實(shí)我也是個(gè)新手,哈哈,一起加油吧?。。?/p>