Javascript 沿路径、曲线和;线
有人知道一个更简单(不太臃肿)的函数/插件来计算自定义scrollpath,比如Joel Besada的jquery.scrollpath吗 我需要的是一种让DOM节点沿着预定义路径移动的方法。我知道Math.cos和Math.sin(沿着曲线移动),但我不是真正的数学天才。好的,明白了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)
// 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
看起来这正是您需要的