有没有人知道一个更简单(不那么臃肿)的函数/插件来计算自定义滚动路径,比如Joel Besada的jquery.scrollpath?
我需要的是一种让DOM-Node沿着预定义的路径移动的方法。我知道Math.cos & Math.sin (沿着曲线移动),但我不是一个真正的数学天才。
发布于 2013-02-01 02:59:38
好了,明白了!
// 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://stackoverflow.com/questions/14617550
复制相似问题