zoukankan      html  css  js  c++  java
  • JavaScript封装缓动动画函数

      //缓动动画
        function animate(element, target) {
            //清理定时器
            clearInterval(element.timeId);
            element.timeId = setInterval(function () {
                //获取元素的当前位置
                var current = element.offsetLeft;
                //移动的步数
                var step = (target - current) / 10;
                step = step > 0 ? Math.ceil(step) : Math.floor(step);
                current += step;
                element.style.left = current + "px";
                if (current == target) {
                    //清理定时器
                    clearInterval(element.timeId);
                }
                //测试代码:
                console.log("目标位置:" + target + ",当前位置:" + current + ",每次移动步数:" + step);
            }, 20);
        }
    

      

  • 相关阅读:
    洛朗级数
    泰勒级数
    中心极限定理
    置信区间公式
    简单随机样本的性质
    极大似然估计
    矩估计法
    摆摊70
    天天去哪吃
    天天和树
  • 原文地址:https://www.cnblogs.com/cuilichao/p/9469682.html
Copyright © 2011-2022 走看看