2

我在网站上使用 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);
        }
    };
});
});

任何指针都非常感谢。谢谢

4

1 回答 1

0

哦,亲爱的我。经过许多不必要的修补和修改,结果证明比我想象的要简单得多。
只需替换y : targety : target-100.
是的,我是个白痴。

于 2015-09-03T12:08:36.753 回答