我在网站上使用 ScrollMagic 有一个锚链接滚动功能,我试图将 scrollTo 目标沿 y 轴偏移 100px,我对 jquery 很陌生,不知道在哪里放置这种指令:
'scrollTop': $target.offset().top - 100
这是我的工作代码(来自:https ://github.com/janpaepke/ScrollMagic/wiki/Tutorial-:-Anchor-Navigation ):
$(document).ready(function() {
// Init controller
var controller = new ScrollMagic.Controller();
// Change behavior of controller
// to animate scroll instead of jump
controller.scrollTo(function(target) {
TweenMax.to(window, 2, {
scrollTo : {
y : target, // scroll position of the target along y axis
autoKill : true, // allows user to kill scroll action smoothly
},
ease : Cubic.easeInOut
});
});
// Bind scroll to anchor links
$(document).on("click", "a[href^=#]", function(e) {
var id = $(this).attr("href");
if($(id).length > 0) {
e.preventDefault();
// trigger scroll
controller.scrollTo(id);
// If supported by the browser we can also update the URL
if (window.history && window.history.pushState) {
history.pushState("", document.title, id);
}
};
});
});
任何指针都非常感谢。谢谢