zoukankan      html  css  js  c++  java
  • 运动框架

    运动框架演变过程
    startMove(iTarget) 运动框架
    startMove(obj, iTarget) 多物体
    startMove(obj, attr, iTarget) 任意值
    startMove(obj, attr, iTarget, fn) 链式运动
    startMove(obj, json) 多值运动
    startMove(obj, json, fn) 完美运动框架

    完美运动框架:(下面是讲解)

    
    
    function startMove(obj, json, fnEnd)//json顶替了之前iTarget的位置
    {
        clearInterval(obj.timer);
        obj.timer=setInterval(function (){

            var bStop=true; //新引进的变量 假设:所有值(width/height/opacity)都已经到达目标了 因 300, height: 101而生 即倘若两个变化差很大肉眼可见无法同时到达
            
            for(var attr in json)
            {
    //
                var cur=0;
                if(attr=='opacity')
                {
                    cur=Math.round(parseFloat(getStyle(obj, attr))*100);
                }
                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;//一旦有一个json元素未达到目标 就改变变量的值
                
             if(attr=='opacity')
                {
                    obj.style.filter='alpha(opacity:'+(cur+speed)+')';
                    obj.style.opacity=(cur+speed)/100;
                }
                else
                {
                    obj.style[attr]=cur+speed+'px';
                }
    //是之前的内容(有iTarget的时候) 现在用上了json+for-in循环
            }
            
            if(bStop) //bstop为真 就是没有执行上面那个if语句 没有东西没到目标
            {
                clearInterval(obj.timer);//关掉定时器
                            
                if(fnEnd)fnEnd();//如果有函数就执行函数
            }
        }, 30);
    }
     

     完美运动框架:可以多个值同时变化

    Json+for-in+新变量(var bStop=true

     

  • 相关阅读:
    luogu P1833 樱花 看成混合背包
    luogu P1077 摆花 基础记数dp
    luogu P1095 守望者的逃离 经典dp
    Even Subset Sum Problem CodeForces
    Maximum White Subtree CodeForces
    Sleeping Schedule CodeForces
    Bombs CodeForces
    病毒侵袭持续中 HDU
    病毒侵袭 HDU
    Educational Codeforces Round 35 (Rated for Div. 2)
  • 原文地址:https://www.cnblogs.com/yundong333/p/10403456.html
Copyright © 2011-2022 走看看