我一起使用 barba.js 和机车滚动,当我单击菜单链接(page2)转到另一个页面时,我有覆盖转换,但是一旦它向下滚动,我就无法向下滚动,我添加了下面的代码
barba.hooks.beforeLeave((data) => {
scroll.destroy();
});
barba.hooks.after((data) => {
scroll.init();
});
我仍然得到相同的结果,请帮助解决这个问题
<body data-barba="wrapper">
<div class="overlayCover"></div>
<ul>
<li><a href="page1.html">Page 1</a></li>
<li><a href="page2.html">Page 2</a></li>
</ul>
<main data-barba="container" data-barba-namespace="page1">
<div class="o-scroll">
<div data-scroll-container>
content here ....
</div>
</div>
</div>
</body>
完整脚本如下
const scroll = new locomotiveScroll({
el: document.querySelector('.o-scroll'),
smooth: true
});
barba.hooks.enter(() => {
window.scrollTo(0, 0);
});
barba.hooks.beforeLeave((data) => {
scroll.destroy();
});
barba.hooks.after((data) => {
scroll.init();
});
barba.init({
sync: true,
transitions: [{
async leave(data) {
const done = this.async();
pageTransition();
await delay(1500);
done();
},
async enter(data) {
contentAnimation();
},
async once(data) {
contentAnimation();
}
}]
});
谢谢