zoukankan      html  css  js  c++  java
  • 原生JS代码封装(抛物线运动)

    function parabola(ele, stop){
            
            //y == a*x^2 + bx + c
            //原点
            var centerpoint = {
                x : ele.offsetLeft,
                y : ele.offsetTop
            }
            //目标点的 相对坐标系位置
            var target = {
                x : stop.offsetLeft - centerpoint.x,
                y : centerpoint.y - stop.offsetTop
            }
            //系数
            var a = -0.0015;
            // b = (y - ax^2)/x
            b = (target.y - a*target.x*target.x)/target.x;
            
            var _x = 0;
            var t = setInterval(function(){
                _x+=8;
                var _y = a*_x*_x + b*_x;
                ele.style.left = _x + centerpoint.x + "px";
                ele.style.top = centerpoint.y - _y + "px";
                
                if(_x >= target.x) {
                    ele.style.left = stop.offsetLeft + "px";
                    ele.style.top = stop.offsetTop + "px";
                    clearInterval(t)
                }
            }, 20);
        }
  • 相关阅读:
    03_线性表
    02_算法与数据结构
    01_python中内置类型的时间复杂度
    00_常见的时间复杂度
    03_docker导出和导入镜像
    09_创建mysql数据库的用户
    14_linux添加主机列表
    13_linux修改主机名
    12_centos7安装好后的网络设置
    00_使用pdb调试python代码
  • 原文地址:https://www.cnblogs.com/sunyang-001/p/10813074.html
Copyright © 2011-2022 走看看