为什么我将鼠标移动上去后他的值不是到400px,而是到391px从而停下来了?
/**
* Created by Administrator on 2016/1/5.
*/
function setMove(obj,sty,goal){
var div =document.getElementById("wrap");
var timer=null;
timer=setInterval(function(){
var ist = 0
if(sty=='opacity'){
ist=Math.round(parseFloat(setStyle(obj,sty))*100);
}else{
ist=parseInt(setStyle(obj,sty));
}
var speed = (goal-ist)/10;
speed= speed>0? Math.ceil(speed):Math.floor(speed);
if(ist == goal){
clearInterval(timer);
}else{
if(sty=='opacity'){
obj.style.filter='alpha(opacity'+(ist + speed)+')';
obj.style.opacity=(ist + speed)/100;
}else {
obj.style[sty] = ist + speed + "px";
}
}
},30);
}
function setStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}