為什么我這個運動動畫 到不了指定值?
<!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 ?什么情況
2016-07-14
可以啊 ,我用的就是你的代碼。不知道什么問題?*{margin: 0;padding: 0;}試試?
2018-08-23
為什么我用火狐也是393px,然后死循環,到不了400px目標值,