原生js运动框架

function getStyle(obj,name)
{
if(obj.currentStyle)
{
return obj.currentStyle[name];
}
else
{
return getComputedStyle(obj,false)[name];
}
}
var timer=null;
function move(obj,what,target){
clearInterval(obj.timer);
obj.timer=setInterval(function()
{
var cur=0;
if(what=='opacity')
{
cur=Math.round(parseFloat(getStyle(obj,what)));
}
else{
var cur=parseInt(getStyle(obj,what));
}
var speed=(target-cur)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(cur==target)
{
clearInterval(obj.timer);
}
else
{
if(what=='opacity')
{
obj.style.filter='alpha(opaity:'+(speed+cur)+')';
obj.style.opacity=(speed+cur)/100;
}
else
{
obj.style.width=cur+speed+'px';
}
}
},30);

上一篇:Typescript 学习笔记三:函数


下一篇:大数据系列-CDH环境中SOLR入数据