所以我试图让 wow.js (和 Animate.css)在我的 WordPress 模板上工作。我已经将它们全部链接得很好(它不会引发任何错误),并且动画确实有效,但由于某种原因,动画是在页面加载时触发的,而不是在页面滚动时触发的。效果是所有动画在页面加载时开始。我相信 wow.js 某个地方有问题,但我似乎无法找出问题所在。
这是我的代码。提前致谢。
在functions.php中:
function theme_styles(){
//Add any css style sheets here
wp_enqueue_style('animate', get_template_directory_uri() .'/css/animate.min.css');
}
function theme_js(){
wp_enqueue_script('wow', get_template_directory_uri() .'/js/wow.min.js',array(),'',true);
}
//Adds all style sheets above to wp
add_action('wp_enqueue_scripts', 'theme_styles');
//Adds all javascript above to wp
add_action('wp_enqueue_scripts', 'theme_js');
在页脚.php 中:
<?php wp_footer(); ?>
<script type="text/javascript">
var wow = new WOW(
{
boxClass: 'wow', // animated element css class (default is wow)
animateClass: 'animated', // animation css class (default is animated)
offset: 0, // distance to the element when triggering the animation (default is 0)
mobile: false // trigger animations on mobile devices (true is default)
}
);
wow.init();
</script>
我还尝试使用另一种方法(在functions.php中)启动wow,但这也不起作用:
//* Enqueue script to activate WOW.js
add_action('wp_enqueue_scripts', 'sk_wow_init_in_footer');
function sk_wow_init_in_footer() {
add_action( 'print_footer_scripts', 'wow_init' );
}
//* Add JavaScript before </body>
function wow_init() { ?>
<script type="text/javascript">
new WOW().init();
</script>
<?php }
在页面模板中(以 front-page.php 为例):
<div class="container-fluid">
<header class="row">
<h1 class="wow fadeInDown">Delivering high quality professional websites for small to medium sized businesses in and around Bournemouth</h1>
</header>
</div>