Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 沿路径、曲线和;线_Javascript_Jquery_Path_Scroll_Jquery Animate - Fatal编程技术网

Javascript 沿路径、曲线和;线

Javascript 沿路径、曲线和;线,javascript,jquery,path,scroll,jquery-animate,Javascript,Jquery,Path,Scroll,Jquery Animate,有人知道一个更简单(不太臃肿)的函数/插件来计算自定义scrollpath,比如Joel Besada的jquery.scrollpath吗 我需要的是一种让DOM节点沿着预定义路径移动的方法。我知道Math.cos和Math.sin(沿着曲线移动),但我不是真正的数学天才。好的,明白了 // Shamelessly stolen and ported from https://github.com/weepy/jquery.path $.fn.arc = function (options)

有人知道一个更简单(不太臃肿)的函数/插件来计算自定义scrollpath,比如Joel Besada的jquery.scrollpath吗

我需要的是一种让DOM节点沿着预定义路径移动的方法。我知道Math.cos和Math.sin(沿着曲线移动),但我不是真正的数学天才。

好的,明白了

// Shamelessly stolen and ported from https://github.com/weepy/jquery.path
$.fn.arc = function (options) {
    options = $.extend({}, {
        center: [0, 0],
        radius: 0,
        start: 0,
        end: 0,
        dir: 1,
        rotate: true
    }, options);

    while (options.start > options.end && options.dir > 0) {
        options.start -= 360;
    }

    while (options.start < options.end && options.dir < 0) {
        options.start += 360;
    }

    var css = {};
    return this.each(function(){
        var self = $(this),
            win = $(window),
            doc = $(document);

        win.scroll(function(){
            var now = 1 - (1 * win.scrollTop() / (doc.height() - win.height())),
                a = (options.start * (now) + options.end * (1 - (now))) * Math.PI / 180;

            css.left = (Math.sin(a) * options.radius + options.center[0] + 0.5) | 0;
            css.top = (Math.cos(a) * options.radius + options.center[1] + 0.5) | 0;

            if(options.rotate){
                css.transform = "rotate(" + Math.atan2(options.center[1] - css.top, options.center[0] - css.left) + "rad)";
            }
            self.css(css);
        });
    });
};
//不知羞耻地从https://github.com/weepy/jquery.path
$.fn.arc=功能(选项){
选项=$.extend({}{
中间:[0,0],
半径:0,
起点:0,
完:0,,
董事:1,
旋转:真
},选项);
while(options.start>options.end&&options.dir>0){
options.start-=360;
}
while(options.start
看起来这正是您需要的