【问题标题】:ScrollMagic : Add offset to anchor scrolling?ScrollMagic:为锚滚动添加偏移量?
【发布时间】:2015-09-02 12:47:19
【问题描述】:

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

非常感谢任何指针。 谢谢

【问题讨论】:

    标签: jquery offset scrollto gsap scrollmagic


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-09
      • 2020-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多