简体   繁体   English

jQuery Waypoints .sticky方法

[英]Jquery Waypoints .sticky Method

So I've done everything that is supposed to happen in order to initialize the jquery waypoints-sticky plugin, but it isn't working: included jquery, waypoints, and waypoints-sticky, and called the function: 因此,我已经完成了初始化jquery waypoints-sticky插件应该做的所有事情,但是它不起作用:包含了jquery,waypoints和waypoints-sticky,并调用了该函数: 在此处输入图片说明在此处输入图片说明

$('.my-element').waypoint('sticky');

However, the console reads ("The sticky method does not exist in jQuery Waypoints."): 但是,控制台读取(“ sticky方法在jQuery Waypoint中不存在。”):

在此处输入图片说明

What could I possibly be missing? 我可能会丢失什么? Nothing online gives me any ideas at all. 网上没有任何东西给我任何想法。 Thanks for your input! 感谢您的输入!

This shortcut requires the jQuery build of Waypoints. 此快捷方式需要jQuery构建Waypoint。

First, include the shortcut script after the main Waypoints script. 首先,在主Waypoints脚本之后添加快捷方式脚本。

<script src="/path/to/lib/jquery.waypoints.min.js"></script>
<script src="/path/to/shortcuts/sticky.min.js"></script>

var sticky = new Waypoint.Sticky({
  element: $('.basic-sticky-example')[0]
})

Have you seen http://imakewebthings.com/waypoints/shortcuts/sticky-elements/ ? 您看过http://imakewebthings.com/waypoints/shortcuts/sticky-elements/吗?

Make sure that everything's getting loaded before your code executes. 在执行代码之前,请确保已加载所有内容。 Try wrapping your code in a $(document).ready() call, like so: 尝试将代码包装在$(document).ready()调用中,如下所示:

$(document).ready(function () {
    $('.my-element').waypoint('sticky');
});

Equivalently, and slightly more concise: 等效地,更简洁一些:

$(function () {
    $('.my-element').waypoint('sticky');
});

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

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