我正在使用locomotive-scroll
Next.js 并且一切正常。但是在路由到不同的页面后,我的卷轴不会破坏,并且 2 个卷轴相互重叠。
路由后如何locomotive-scroll
在 Next.js 中正确重新初始化?
我的代码示例:
function MyApp({ Component, pageProps }) {
useEffect(() => {
import("locomotive-scroll").then((locomotiveModule) => {
let scroll = new locomotiveModule.default({
el: document.querySelector("[data-scroll-container]"),
smooth: true,
smoothMobile: false,
resetNativeScroll: true,
});
scroll.destroy(); //<-- DOESN'T WORK OR IDK
setTimeout(function () {
scroll.init();
}, 400);
});
});
return (
<main data-scroll-container>
<Component {...pageProps} />
</main>
);
}