• 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);
        }
    

      

  • 相关阅读:
    Lucene
    SQL优化以及索引
    Mysql优化
    RocketMQ
    RocketMQ
    Session共享
    Linux安装Nginx
    初识nginx
    跨域,防止表单重复提交
    HttpClient案例
  • 原文地址:https://www.cnblogs.com/cuilichao/p/9469682.html
Copyright © 2020-2023  润新知