<!doctype?html>
<html>
<head>
<meta?charset="utf-8">
<title>多物體運(yùn)動(dòng)</title>
<style>
*{list-style:none;margin:0px;padding:0px;}
ul?li{width:200px;
??height:100px;
??background:yellow;
??margin:50px?auto;
??border:#000000?solid?1px;
??filter:alpha(opacity:30);
??opacity:0.3;
??}
</style>
<script>
window.onload=function(){
var?li1=document.getElementById('li1')
li1.onmouseover=function(){
startMove(li1,{'width':400,'height':200,opacity:100,borderWidth:50})
}
li1.onmouseout=function(){
startMove(li1,{'width':200,'height':100,opacity:30,borderWidth:1})
}
}
//var?alpha=30
function?startMove(obj,json,fn){
clearInterval(obj.timer)
obj.timer=setInterval(function(){
//var?icur=0
var?flag=true
for(var?attr?in?json){
if(attr=='opacity'){
var?icur=Math.round(parseFloat(getStyle(obj,[attr]))*100)
}
else{
var?icur=parseInt(getStyle(obj,[attr]))
}
var?speed=(json[attr]-icur)/8
speed=speed>0?Math.ceil(speed):Math.floor(speed)
if(icur?!=?json[attr]){
flag=false;
}
if(attr=='opacity'){
obj.style.filter='alpha(opacity:'+(icur+speed)+')'
obj.style.opacity=(icur+speed)/100;
}
else{
obj.style[attr]=icur+speed+'px';
}
}
if(flag){
clearInterval(obj.timer)
if(fn){fn()}
}
},50)
}
function?getStyle(obj,attr){
if(obj.currentStyle){
return?obj.currentStyle[attr]
}
else{
return?getComputedStyle(obj,false)[attr]
}
}
</script>
</head>
<body>
<ul>
<li?id="li1"></li>
</ul>
</body>
</html>當(dāng)邊框的目標(biāo)寬度大于8時(shí),運(yùn)行結(jié)果總是比目標(biāo)寬度小7;當(dāng)邊框的目標(biāo)寬度小于等于8時(shí),即使原始寬度不是1,運(yùn)行結(jié)果也總是回變成1;導(dǎo)致這個(gè)bug的原因是什么額,求大神解答?
js動(dòng)畫,邊框?qū)挾冗_(dá)不到目標(biāo)值,運(yùn)行結(jié)果總是比目標(biāo)值小7.
kx00012kx
2016-08-13 09:30:18