作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我今天刚刚尝试了路点,因为它看起来棒极了,
但是,我很难让事情顺利进行,
第一次简单测试,完美运行,
$('.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%'});
关于jquery - $(this).addClass ('why-you-no-working' );不在航点上工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27874280/
我是一名优秀的程序员,十分优秀!