doudi2833 2016-05-04 16:34
浏览 18

Waypoints.js与wordpress

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.

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' );

And then in the javascript:

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

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?

Thanks!

  • 写回答

1条回答 默认 最新

  • dongxiaoxiao1983 2017-04-04 06:16
    关注

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

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

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测