为什么我这个运动动画 到不了指定值?
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style> #hd{ width:200px; height:100px; background:#F05053; } </style> <script type="text/javascript"> window.onload=function(){ var h = document.getElementById("hd"); h.onmouseover= function(){ move(h,"width",400); } h.onmouseout= function(){ move(h,"width",200); } } function move (obj,attr,iTarget){ clearInterval(obj.timer); obj.timer = setInterval(function(){ var icurr = parseInt(getStyle(obj,attr)); var speed = (iTarget-icurr)/7; speed = speed<0?Math.floor(speed):Math.ceil(speed); if(icurr == iTarget){ clearInterval(obj.timer); }else{ obj.style[attr] = icurr+speed+"px"; } },30); } function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; }else{ return getComputedStyle(obj,false)[attr]; } } </script> </head> <body> <p id="hd"></p> </body> </html>
为什么我这个宽度 只能到394呢 到不了400 什么情况