码迷,mamicode.com
首页 > 其他好文 > 详细

基础 - 运动框架

时间:2016-08-10 19:02:57      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

function  funStyle(obj,attr)
{
return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj,false)[attr];
}
function funStartMove(obj,json,fnFinish,time)
{
funStopMove(obj);
funMove(obj,json,fnFinish);
obj.timer = setInterval(function(){
funMove(obj,json,fnFinish);
},time);
}
function funStopMove(obj)
{
clearInterval(obj.timer);
}
function funMove(obj,json,fnFinish)
{
obj.bStop = true;
for (var attr in json) {
funPartMove(obj,attr,json[attr]);
}
if (obj.bStop) {
funStopMove(obj);
if (fnFinish) fnFinish();
}
}
function funPartMove(obj,attr,iTarget)
{
if (attr=="opacity") {
obj.myValue = Math.round(parseFloat(funStyle(obj,attr))*100);
}else{
obj.myValue = parseInt(funStyle(obj,attr));
}
if (obj.myValue!=iTarget) {
// 匀速运动
obj.iSpeed = obj.myValue<iTarget?1:-1;
//缓冲运动
// obj.iSpeed = (iTarget-obj.myValue)/30;
// obj.iSpeed =obj.iSpeed>0?Math.ceil(obj.iSpeed):Math.floor(obj.iSpeed);
obj.myValue += obj.iSpeed;
if (attr=="opacity") {
obj.style.filter = "alpha(opacity:"+obj.myValue+")";
obj.style.opacity = obj.myValue*0.01;
}else{
obj.style[attr] = obj.myValue+"px";
}
if (obj.myValue!=iTarget) obj.bStop = false;
}
}

基础 - 运动框架

标签:

原文地址:http://www.cnblogs.com/WeWeZhang/p/5757770.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!