带有 wordpress 的 Waypoints.js [英] Waypoints.js with wordpress

查看:15
本文介绍了带有 wordpress 的 Waypoints.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 wordpress 网站,我需要触发用户滚动以触发不同的事件并隐藏/显示一些图像,所以 Waypoints.js 非常适合它.

I'm developing a wordpress site and I need to trigger the user scroll in order to fire different events and hide/show some images, so Waypoints.js is perfect for it.

但是,我尝试了不同的尝试以使其正常工作,但没有任何结果.我将它添加为functions.php文件中的一个函数,如下所示:

However I've tried different attempts to make it work with no results. I add it as a function on functions.php file, like this:

function waypoints_method() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js", false, null);
    wp_enqueue_script('jquery');
    wp_enqueue_script('waypoints', get_stylesheet_directory_uri() . '/vendor/waypoints/lib/jquery.waypoints.min.js');
}
add_action( 'wp_enqueue_scripts', 'waypoints_method' );

然后在 javascript 中:

And then in the javascript:

jQuery(document).ready(function($) {
     $('.waypoint').waypoint(function() {
            alert('You have scrolled to my waypoint.');
        });
}

我唯一得到的是在调整浏览器大小时的 console.log.那么,我需要做什么才能让它发挥作用?或者,我可以使用 Waypoints.js 的替代品吗?

The only thing I get it is to console.log when resizing the browser. So, what I need to do in order to make it work? Or, there is any alternative to Waypoints.js that I could use?

谢谢!

推荐答案

Waypoints is using $ 访问 jQuery,但使用 WordPress,您需要将 jQuery 称为 jQuery.

Waypoints is using $ to access jQuery, but with WordPress you need to refer to jQuery as jQuery.

我发现我不得不使用无框架版本的Waypoints让它与 WordPress 一起使用.

I found that I had to use the no framework version of Waypoints to get it working with WordPress.

这篇关于带有 wordpress 的 Waypoints.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆