简体   繁体   English

无法在 WordPress 站点中使用 Barba js 进行简单的页面转换

[英]Cannot make a simple page transition work with Barba js in a WordPress site

I'm developing a custom theme for WP and need to make page transitions similar to this website https://www.instrument.com/我正在为 WP 开发自定义主题,需要进行类似于此网站https://www.instrument.com/的页面转换

Barba.js seems like a perfect solution for these purposes.对于这些目的, Barba.js似乎是一个完美的解决方案。 However, the entire DOM tree always refreshes instead of just the content.但是,整个 DOM 树总是会刷新,而不仅仅是内容。

Here is what I have:这是我所拥有的:

header.php

<html>
  <head>
    <meta name="viewport" content="width=device-width">
    <?php wp_head();?>
  </head>
  <body data-barba="wrapper"
    <?php
      if ( get_field('is_dark_theme') ) {
        body_class( 'bg-dark text-light' );
      } else {
        body_class();
      }
      ?>
  >

  <nav>
    ...
  </nav>

  <main data-barba="container" data-barba-namespace="home">

footer.php

    </main>
  </div>

  <?php wp_footer();?>

  </body>
</html>

In my main script file which is injected right before the closing of the body tag, I have the following:在 body 标记结束之前注入的主脚本文件中,我有以下内容:

(function () {
  barba.init({
    transitions: [{
      name: 'default-transition',
      leave() {
        console.log('leave');
      },
      enter() {
        console.log('enter');
      }
    }]
  });
})();

When I click on the link in the navbar, there is a leave console output but then the entire page is loaded again as if Barba was never there.当我单击导航栏中的链接时,有一个leave控制台 output,但随后整个页面再次加载,就好像 Barba 从未出现过一样。 I never see enter output.我从来没有看到enter output。

Is it possible to use Barba with WP in the first place?是否可以首先将 Barba 与 WP 一起使用? If so, what am I doing wrong?如果是这样,我做错了什么?

I appreciate your help.我感谢您的帮助。

Turns out the problem was with the default timeout in Barba.事实证明问题出在 Barba中的默认超时 It was set to 2000ms and my pages took longer than that.它被设置为 2000 毫秒,我的页面花费的时间比这更长。 If the page takes longer than the timeout, Barba gives up and the entire page refreshes.如果页面花费的时间超过超时时间,Barba 将放弃并刷新整个页面。

I've set the timeout to a higher value and it works perfectly.我已将超时设置为更高的值,并且效果很好。

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

相关问题 Barba Js 在第一次链接上重新加载页面 - Barba Js reloads page on first time links 无法让我看似简单的js提交表单功能在wordpress上工作 - cannot get my seemingly simple js submit form function to work on wordpress WordPress 站点的 PHP 站点无法仅在登录页面上创建 cookie - PHP at WordPress site cannot create cookie only on Login page 在我的wordpress网站上添加了一个页面,但我无法使用Filezilla对其进行访问 - Added a page to my wordpress site and I cannot access it using Filezilla 试图让简单的WordPress自定义页面PHP插入工作 - Trying to get simple wordpress custom page PHP insert to work 如何仅在站点页面中显示过渡消息 - How to display transition messages in site page only 在拥有 WordPress 站点时,如何使自定义 php web 页面在 ZFDE316856817FE53586DZ 环境之外可见? - While having WordPress site, how do I make a custom php web page viewable outside the WordPress environment? 无法使is_front_page在Wordpress页脚中工作 - Cannot get is_front_page to work in Wordpress footer 如何在WordPress中制作自定义模板作为受密码保护的页面? - How to make a custom template in WordPress work as a password protected page? 作业站点的简单配置文件页面 - simple profile page for a job site
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM