gpt4 book ai didi

jquery - $(this).addClass ('why-you-no-working' );不在航点上工作?

转载 作者:行者123 更新时间:2023-12-01 00:40:29 25 4
gpt4 key购买 nike

我今天刚刚尝试了路点,因为它看起来棒极了,

但是,我很难让事情顺利进行,

第一次简单测试,完美运行,

$('.parallax').waypoint(function() {
alert('I work');
});

但是当我使用 $(this) 时,它不起作用,例如

$('.parallax').waypoint(function() {
$(this).addClass('why-you-no-working');
});

您可以从此处查看示例 -> http://jsfiddle.net/4D3bH/425/

第二个框应该有黑色背景颜色而不是蓝色,但由于某种原因它的简单不起作用,

如果我使用类似下面的东西,它工作得很好,它

$('.parallax').waypoint(function() {
$('.parallax').addClass('why-you-no-working');
});

花了近三个小时试图让它工作,但没有运气,

请帮忙:)

最佳答案

在这种情况下,this 并不引用 DOMElement 。您可以引用DOMElement ,在回调内部,通过属性 this.element

$('.parallax:nth-of-type(2)').waypoint(function() {        
$(this.element).addClass('why-you-no-working');
},{offset: '1%'});

Example

关于jquery - $(this).addClass ('why-you-no-working' );不在航点上工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27874280/

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