Barba.js 触发锚链接上的转换

发布于 2025-01-12 14:25:31 字数 487 浏览 1 评论 0原文

这里是 Barba.js 的菜鸟用户。

我在 Joomla 网站上使用 Barba.js,几乎一切都工作正常。

我的问题是 Barba.js 还在我的链接上触发页面转换,并且它重定向到主页。

<a href="#section3">Click here</a>

这是我的 mydomain.com/index.php/secondPage 上的元素

当我单击该元素时,网站 barba-transitions 到 mydomain.com/index.php#section3

但是如果我转到我的第二页刷新页面,锚链接就可以正常工作。

我缺少什么?

非常感谢。

quite noob user of Barba.js here.

I am using Barba.js on a Joomla website, and almost everything is working fine.

My problem is that Barba.js is triggering the page transition also on my anchor links, and it redirects to the homepage.

<a href="#section3">Click here</a>

This is the element that I have on my mydomain.com/index.php/secondPage

When I click on the element, the site barba-transitions to mydomain.com/index.php#section3

But if I go to my secondPage and refresh the page, the anchor link works perfectly.

What am I missing?

Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把昨日还给我 2025-01-19 14:25:31

如果您不希望 Barba.js 处理某些链接,您可以向它们添加一个类 - 这样 Barba 就知道这不是 Barba 的事。
例如 - 添加 Prevent-barba 类,然后在 Barba init 函数参数中添加:

prevent: ({ el }) => el.classList && el.classList.contains('prevent-barba'),

希望有帮助:)

If you don't want certain links to be processed by Barba.js you can add a class to them - so the Barba knows it's not Barba business.
For example - add prevent-barba class and then in Barba init function parameters add:

prevent: ({ el }) => el.classList && el.classList.contains('prevent-barba'),

Hope that helps :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文