问答详情
源自:4-4 任意属性值(二)

为什么我这个在火狐里面不行呢

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>无标题文档</title>

</head>

<style>

*{margin:0; padding:0;}

ul,li{list-style:none;}

ul li{

width:200px; height:100px; background:yellow; margin-bottom:20px; border:4px solid #333; filter:alpha(opacity:30);opacity:0.3;

}

</style>

<script>


window.onload=function(){

var aLi=document.getElementsByTagName('li');

for(var i=0;i<aLi.length;i++){

aLi[i].timer=null;

aLi[i].onmousemove=function(){

startMove(this,400)

}

aLi[i].onmouseout=function(){

startMove(this,200);

}

}

}

function getStyle(obj,attr){

if(obj.currentStyle){

return obj.currentStyle[attr];

}else{

return getComputedStyle(obj,false)[attr];

}

}

function startMove(obj,iTarget){

clearInterval(obj.timer);

obj.timer=setInterval(function(){

var icur=parseInt(getStyle(obj,'width'))

var speed=(iTarget-icur)/8;

speed=speed>0?Math.ceil(speed):Math.floor(speed);

if(icur==iTarget){

clearInterval(obj.timer)

}else{

obj.style['width']=icur+speed+'px'

}

})

}

</script>

<body>

<ul>

<li></li>

<li></li>

<li></li>


</ul>

</body>

</html>


提问者:星期 2016-11-21 15:09

个回答

  • stone310
    2016-11-21 23:02:50
    已采纳

    setInterval后面没有加上时间,系统就默认为0

  • WANG655554158315
    2016-11-21 17:20:24

    html4