简体   繁体   English

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

[英]Barba.js triggering transition on anchor links

quite noob user of Barba.js here. Barba.js 的新手用户在这里。

I am using Barba.js on a Joomla website, and almost everything is working fine.我在Joomla网站上使用 Barba.js,几乎一切正常。

My problem is that Barba.js is triggering the page transition also on my anchor links, and it redirects to the homepage.我的问题是 Barba.js 也在我的链接上触发页面转换,它重定向到主页。

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

This is the element that I have on my mydomain.com/index.php/secondPage这是我在 mydomain.com/index.php/secondPage 上的元素

When I click on the element, the site barba-transitions to mydomain.com/ index.php#section3当我单击该元素时,站点barba -transitions 到 mydomain.com/index.php#section3

But if I go to my secondPage and refresh the page, the anchor link works perfectly.但是,如果我转到我的secondPage刷新页面,则锚链接可以完美地工作。

What am I missing?我错过了什么?

Thank you very much.非常感谢。

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.如果您不希望 Barba.js 处理某些链接,您可以向它们添加一个类 - 所以 Barba 知道这不是 Barba 业务。 For example - add prevent-barba class and then in Barba init function parameters add:例如 - 添加 prevent-barba 类,然后在 Barba 初始化函数参数中添加:

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

Hope that helps :)希望有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM