鏈?zhǔn)秸{(diào)用一定要鼠標(biāo)移出再移進(jìn)去才會執(zhí)行第二個程序 為什么?
function getStyle (obj,attr) {
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,null)[attr];
}
}
function startMove(obj,json,func){
var flag=true;
clearInterval(obj.timer);
obj.timer=setInterval(function(){
for(var attr in json){
//取當(dāng)前值
var iCur=0;
if(attr=='opacity')
{
iCur=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else{
iCur=parseInt(getStyle(obj,attr));
}
//算速度
var speed=(json[attr]-iCur)/10;
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(func){
func();
}
}
},50)
}
2016-01-25
將?
放在 定時器里面, for循環(huán)外面