alpha屬性的問題
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>js多物體速度動畫</title>
<style type="text/css">
*{margin:0;padding:0;}
ul,li{list-style:none}
ul li{width:200px;height:100px;background:#1DF467;margin-bottom:20px}
</style>
<script type="text/javascript">
window.onload=function(){
var oLi=document.getElementsByTagName("li");
for(var i=0;i<oLi.length;i++){
oLi[i].timer=null;
oLi[i].onmouseover=function(){
startMove(this,400);
}
oLi[i].onmouseout=function(){
startMove(this,200);
}
? }
}
? ? ? ? function startMove(obj,iTarget){
? ? ? ? ? ? var oLi=document.getElementsByTagName("li");
? ? ? ? ? ? clearInterval(obj.timer);
? ? ? ? ? ? obj.timer=setInterval(function(){
? ? ? ? ? ? ? ?var speed=(iTarget-obj.offsetWidth)/10;
? ? ? ? ? ? ? ?speed=speed>0?Math.ceil(speed):Math.floor(speed);
? ? ? ? ? ? ? ?if(obj.offsetWidth==iTarget)
? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ?clearInterval(obj.timer);
? ? ? ? ? ? ? ? ? }?
? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ?obj.style.width=obj.offsetWidth+speed+"px";
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? },30)
? ? ? ? }
??
</script>
</head>
<body>
<ul>
? <li></li>
? <li></li>
? <li></li>
</ul>
</body>
</html>
在window.onload的for循環(huán)oDiv[i].alpha中定義了alpha屬性,在startMove()函數(shù)中就可以直接用嗎,不用考慮作用域嗎?
2017-03-10
定義for循環(huán)里面的alpha透明度屬性應該只是為了后面的clearInterval(obj.timer);可以關閉