Day_21
完美运动框架
function getStyle(obj, name)
{
if(obj.currentStyle)
{
return obj.currentStyle[name];
//返回所有样式声明,(包括内部、外部、内联)按css层叠规则作用于元素的最终样式,IE和Opera
}
else
{
return getComputedStyle(obj)[name];
//获取当前元素所使用的css属性值,Chrome、火狐和Safari
}
}
function startMove(obj, json, fnEnd)
//三个参数,第一个选取元素,第二个JSON数组(样式列表),第三个回调函数
{ clearInterval(obj.timer);
obj.timer=setInterval(function (){
var bStop=true;
for(var attr in json)
{
var cur=0;
if(attr=='opacity')
//透明度单独判断执行
{
cur=Math.round(parseFloat(getStyle(obj, attr))*100);
//Math.round获取小数的四舍五入值,兼容IE7以下
}
else
{
cur=parseInt(getStyle(obj, attr));
}
var speed=(json[attr]-cur)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
//向上取整
if(cur!=json[attr])
bStop=false;
if(attr=='opacity')
{
obj.style.filter='alpha(opacity:'+(cur+speed)+')';
obj.style.opacity=(cur+speed)/100;
}
else
{
obj.style[attr]=cur+speed+'px';
}
}
if(bStop)
{
clearInterval(obj.timer);
if(fnEnd)fnEnd();
}
}, 30);
}
最近准备搭建自己的服务器了,可能会更新搭建服务器的详细过程,很忙,以后可能一周更一篇文章,随笔这种东西,有空就写写。
还有我的博客最近在装修,板式有点不好看T T。

浙公网安备 33010602011771号