有没有办法将其他参数传递给 scrollTarget 回调函数?

Is there a way to pass other parameters to the scrollTarget callback function?

我正在查看 ScrollMagic 的文档。我看到我可以使用回调函数来更改滚动行为,如下所示:

controller.scrollTo(function (newScrollPos) {
    $("body").animate({scrollTop: newScrollPos});
});

有没有办法给这个函数传递更多的参数?对于某些特定的 links/anchors,我想使用一个偏移量。我一直无法弄清楚如何传递更多参数,或者如何从回调中获取 ScrollTarget。

此函数仅用于接收数字,因为它应该做的就是创建移动到该数字的自定义滚动行为。

但是您可以使用 this.

在回调中引用控制器

将元素或场景位置转换为滚动位置的功能(如果您向 controller.scrollTo 提供元素或场景)甚至在调用自定义回调之前就已处理。

因此,为了让它在特定情况下使用某些偏移量,您需要在实际调用函数之前处理它。
例如在您的点击处理程序中。

这是一些伪代码:

anchor.on(click, function() {
    if (this is an exception) {
         var customPos = targetElement.offset().top + offset;
         controller.scrollTo(customPos);
    } else {
         controller.scrollTo(targetElement);
    }
});