有没有老师的move.js
麻烦给一下
麻烦给一下
2016-03-29
function startMove(obj,json,fn){
var flag = true;
clearInterval(obj.timer);
obj.timer = setInterval(function(){
for(var attr in json){
//取当前值;
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)/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();
}
}
}
},30);
}
//获取样式;
function getStyle(obj,attr){
if (obj.currentStyle){
return obj.currentStyle[attr];//针对IE浏览器;
}else{
return getComputedStyle(obj,false)[attr];//针对大多数浏览器;
}
}
举报