一二得三
2017-01-10 00:20
function startMove(obj,json,fn){ clearInterval(obj.timer); obj.timer = setInterval(function(){ var all = 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)/10; speed = speed>0?Math.ceil(speed):Math.floor(speed); if(icur != json[attr]){ all = false; } //判断是否为透明度 if(attr == "opacity"){ obj.style[attr] = (icur + speed)/100;; }else{ obj.style[attr] = icur + speed + "px"; } if(all){ clearInterval(obj.timer); if(fn){ fn(); } } } },30); } //解决IE兼容 function getStyle(obj,attr) { var style = null; if(window.getComputedStyle){ style = window.getComputedStyle(obj, null)[attr]; }else{ style = obj.currentStyle[attr]; } return style; }
if(all){
clearInterval(obj.timer);
}
放在属性变化的后面
JS动画效果
113925 学习 · 1443 问题
相似问题
回答 2
回答 2