jquery - 滚动魔法 : Add offset to anchor scrolling?

标签 jquery offset scrollto gsap scrollmagic

我在网站上有一个使用ScrollMagic的 anchor 链接滚动功能,我试图将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);
        }
    };
});
});

非常感谢任何指点。 谢谢

最佳答案

哦亲爱的我。 经过大量不必要的修补和修改,答案比我想象的要简单得多。
只需将 y : target 替换为 y : target-100
是的,我是个白痴。

关于jquery - 滚动魔法 : Add offset to anchor scrolling?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32353599/

相关文章:

javascript - 在选项中解析JSON响应值

apache-kafka - Kafka时间戳顺序是否与偏移量相对应?

javascript - jQueryscrollTo 插件不工作

javascript - 如何使用 localscroll.js 进行水平导航

spring-boot - 如何在kafka监听器方法中寻找特定的偏移量?

javascript - jquery 中的 ScrollTo()

jquery - Yii2:验证屏蔽输入

javascript - 仅将样式应用于可编辑内容中的选定文本 <p>

javascript - 如何从jquery数据表中的ajax调用获取动态列标题和结果

c++ - 这是有效的 ANSI C++ 代码吗?尝试在编译时生成结构成员的偏移量