jquery-waypoints - `this.previous().previous().element == this.element`?
问题描述
我正在将我的代码从 jquery-waypoints 2.x 升级到 4.x,并发现与this.previous()
. 我发现在正确时间触发的处理程序中this.element
是正确的。但是,this.previous().element
用路标指向 DOM 中的下一个元素,并this.previous().previous().element
指向与this.element
. 我可以在代码中设置一个断点并对其进行验证this.previous().previous().element == this.element
。
我不得不想象我做错了什么,或者这是一个错误。我在 v4.0.1 上,我使用的是 jQuery 版本。我像这样绑定我的航点:
$selector.waypoints(
function goingUp(direction) {
console.log(this.previous().previous().element == this.element); // true
console.log(this.next().previous().element == this.element); // true
}, {
offset: offsetCalculator(this),
});
解决方案
问题原来是航路点的分组。该.previous()
航路点(不计入分组)在文档顺序中出现的时间晚于当前航路点。一旦我将组添加到航点,.previous()
并按.next()
预期工作。
推荐阅读
- ios - 如何选择 CollectionViewCell 内的 TableViewCell
- azure-pipelines - In ADF V2 - how to append date ("yyyyMMdd")) to filename dynamically for S3 dataset
- javascript - React-Native 中的右下对齐(使用 Flex-box)不起作用
- regex - 如何使用正则表达式格式化此 txt 文件
- java - 如何创建支持 Intelllij 项目结构的 maven 项目?
- android - iOS 或 Android 应用程序可以与其他应用程序交互推送通知交互吗?
- python - 用pandas加载CSV数据时,第一行被误认为是标题
- java - 为什么袋子被认为是无序的?
- c++ - Leetcode 寻找最长单值路径的问题
- javascript - 我正在创建一个测验,并想知道我是否必须获得每个选择的价值,或者是否可以快速完成