<!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 什么情况

可以啊 ,我用的就是你的代码。不知道什么问题 *{margin: 0;padding: 0;}试试
为什么我用火狐也是393px,然后死循环,到不了400px目标值,