barbajs - Barba.js 和 locomotive-scroll 不兼容?
问题描述
我已经尝试过 barba.js 和 locomotive-scroll 工作(我也尝试过 scrollmagic),但我没有让它正常工作。如果我将 locomotive-scroll 放在 about 页面上并重新加载浏览器,它可以工作,但如果我从那里转到主页并返回 about 页面,它会给我一个错误并停止工作。与其他脚本没有问题,这就是为什么我认为一定有一些不兼容的原因。我尝试了很多方法,但它们都给了我一个错误。最后一个是:
$(function () {
barba.init({
sync: true,
cacheIgnore: false,
transitions: [
{
async leave(data) {
const done = this.async();
pageTransition();
await delay(1000);
done();
},
async enter(data) {
contentAnimation();
},
async once(data) {
contentAnimation();
},
},
],
views: [{
namespace: 'about-section',
beforeEnter({ next }) {
let script = document.createElement('script');
script.src = 'http://127.0.0.1:5000/locomotive-scroll.js';
next.container.appendChild(script);
}
}]
});
});
解决方案
有点晚了,但请添加一个示例,以便我们调试它。
根据我的猜测,如果您多次添加相同的脚本 -> locomotive-scroll.js,可能是这样。
它也可能来自 async/await 语法。我有一个类似的问题并删除它,解决了它。
barba.init({
sync: true,
cacheIgnore: false,
transitions: [
{
leave(data) {
pageTransition();
},
enter(data) {
contentAnimation();
},
once(data) {
contentAnimation();
},
},
],
views: [{
namespace: 'about-section',
beforeEnter({ next }) {
let script = document.createElement('script');
script.src = 'http://127.0.0.1:5000/locomotive-scroll.js';
script.setAttribute('id', 'loco-scroll-id');
next.container.appendChild(script);
},
beforeLeave({current}) {
current.container.querySelector('loco-scroll-id').remove();
}
}]
});
另外,还有一个问题,是故意只在about页面中使用机车卷轴吗?如果没有,您可以简单地将它添加到 barba-container 之外,这样每次更改链接时它都不会重新加载它。
推荐阅读
- powershell - Windows 任务计划程序 Powershell 脚本完成并重新启动
- java - 通过左连接表/Querydsl 上的 QBean 映射具有空属性的对象
- linux - 从 bash 脚本打开 iTerm2 并运行命令
- javascript - 使用 geofirestore 反应原生 Firebase 云功能
- python - 更高效的时间增量计算python 3
- motordriver - 计算启动停止命令后步进电机的停止时间
- wordpress - 使用 apache proxypass 重定向到 /blog (wordpress)
- scala - 在 Spark Streaming 中处理太晚的数据
- r - 发生错误“权重总和不为 1”,但它们总和为 1(R 的 MCDM 包)
- javascript - 可以在 Vuex 中使任意对象具有响应性吗?