• 原生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);
        }
  • 相关阅读:
    2019牛客暑期多校训练营(第三场)B题、H题
    2019牛客暑期多校训练营(第四场)k题、j题
    Manacher算法 & Palindrome
    HDU 3336——Count the string
    判断一个点是否在三角形内
    P1052 过河
    P1353 [USACO08JAN]跑步Running
    hdu 1686 Oulipo
    Cyclic Nacklace HDU
    高精地图技术分析
  • 原文地址:https://www.cnblogs.com/sunyang-001/p/10813074.html
Copyright © 2020-2023  润新知