简体   繁体   English

Barba JS 向 DOM 添加脚本

[英]Barba JS adding scripts to the DOM

barba.init({ transitions: [ {
      name: 'general-transition-opacityfade',
      once({next}){
        animationEnter(next.container)
      },
      leave: ({current}) => animationLeave(current.container),
      enter({next}){
        animationEnter(next.container); }},

Re-run my JS script using Barba.JS Is there a way to add a script to the DOM and run on page enter?使用 Barba.JS 重新运行我的 JS 脚本有没有办法将脚本添加到 DOM 并在页面输入时运行?

You can specify what barba can do before enter after the transition that leads you to the new page.您可以在引导您进入新页面的转换之后指定 barba 在进入之前可以执行的操作。

For example, if you want to execute a script or a just a piece of code to the next transition you can use this.例如,如果您想执行一个脚本或只是一段代码到下一个转换,您可以使用它。

 barba.init({ views: [{ namespace: 'index', beforeLeave(data) { // do something before leaving the current `index` namespace } }, { namespace: 'contact', beforeEnter(data) { // do something before entering the `contact` namespace } }] });

you can find the 'namespace' tag in every single HTML doc that you create and want to link with barbajs hope this works for you.您可以在您创建并希望与 barbajs 链接的每个 HTML 文档中找到“命名空间”标签,希望这对您有用。

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

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