JavaScript运动学相关

Posted JohnRey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript运动学相关相关的知识,希望对你有一定的参考价值。

<script type="text/javascript">
        function getStyle(obj,name){
            if(obj.currentStyle){
                return obj.currentStyle[name];
            }else{
                return getComputedStyle(obj,false)[name];
            }
        }

        functon startMove(obj,attr,iTarget){
            clearInterval(obj.timer);
            obj.timer=setInterval(function(){
                var cur=0;
                if(attr=="opacity"){
                    cur=Math.round(parseFloat(getStyle(obj,attr))*100);
                }else{
                    cur=parseInt(getStyle(obj,attr));
                }
                var speed=(iTarget-cur)/6;
                speed=speed>0?Math.ceil(speed):Math.floor(speed);
                if(cur==iTarget){
                    clearInterval(obj.timer);
                }else{
                    if(attr=="opacity"){
                        obj.style.filter="alpha(opcity:"+(cur+speed)+")";
                        obj.style.opacity=(cur+speed)/100;
                    }else{
                        obj.style[attr]=cur+speed+"px";
                    }
                }
            },30);
        }
    </script>

 

以上是关于JavaScript运动学相关的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段12——JavaScript的Promise对象

VSCode自定义代码片段12——JavaScript的Promise对象

30秒就能看懂的JavaScript 代码片段

保留对附加节点 javascript 的引用

几个关于js数组方法reduce的经典片段

常用Javascript代码片段集锦