gpt4 book ai didi

javascript - 为什么我不能 destroy() 这些路标?

转载 作者:行者123 更新时间:2023-11-30 00:14:10 24 4
gpt4 key购买 nike

我正在处理的网站使用的是 jquery waypoints 版本 3.1.1。我可以像这样从它的处理程序中销毁一个航路点:

var foo = $('#myElem').waypoint({
handler: function() {
// do something
this.destroy();
},
offset: 'bottom-in-view'
});

但不是这样的:

foo.destroy();

我得到错误:

foo.destroy is not a function

我也不能从上下文中销毁它:

var ctx = Waypoint.Context.findByElement($('#myElem'));
ctx.destroy();

我得到错误:

Cannot read property 'destroy' of undefined

我可以销毁航路点的唯一方法是从处理程序内部或使用 destroyAll:

Waypoint.destroyAll();

但我不能使用 destroyAll,因为页面上还有其他我不想销毁的 wyapoints。理想情况下,我可以像这样在每个航路点的基础上做到这一点:

foo.destroy();

或至少在上下文的基础上。这里有什么问题,我正在关注文档但没有得到预期的结果。可能是因为我使用的是旧版本?

最佳答案

foo 是一个数组,因此您需要这样写:

foo[0].destroy();

还可以从 imakewebthings.com/waypoints 考虑这一点:

There is one major difference between using the $.fn.waypoint method with versions 2.0 and 3.0. In 2.0, the same jQuery object was returned for chaining purposes, as is common among core jQuery methods. In 3.0, an array of Waypoint instances is returned.

关于javascript - 为什么我不能 destroy() 这些路标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35371812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com