不知道错在哪了??
<!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]; } }
为什么没反应呢??