jquery 航路点插件无法正常工作
jquery waypoint plugin does not work properly
在我的代码中,$(this) 在 jquery 航路点函数中不起作用,没有 $(this) 一切正常
<script>
$('.team-member').waypoint(function (){
$(this).addClass('bgr');
}, {
offset: '70%'
});
</script>
сss
.bgr {
background: red;
}
有什么想法吗?
使用 Waypont 插件的灵活方式是这样做
var waypoint = new Waypoint({
element: document.getElementById('waypoint'),
handler: function(direction) {
console.log('Scrolled to waypoint!')
}
})
你也可以试试这个
$('.team-member').waypoint(function (){
var thisE = $(this)[0]['element'];
$(thisE).addClass('bgr');
}, {
offset: '70%'
});
在你的例子中,$(this)
指的是航路点对象,而不是特定的 dom 元素,这就是为什么你的代码 brakes.Console 记录 $(this)
,你会看到。
$('.team-member').waypoint(function (){
console.log( $(this) )
}, {
offset: '70%'
});
在我的代码中,$(this) 在 jquery 航路点函数中不起作用,没有 $(this) 一切正常
<script>
$('.team-member').waypoint(function (){
$(this).addClass('bgr');
}, {
offset: '70%'
});
</script>
сss
.bgr {
background: red;
}
有什么想法吗?
使用 Waypont 插件的灵活方式是这样做
var waypoint = new Waypoint({
element: document.getElementById('waypoint'),
handler: function(direction) {
console.log('Scrolled to waypoint!')
}
})
你也可以试试这个
$('.team-member').waypoint(function (){
var thisE = $(this)[0]['element'];
$(thisE).addClass('bgr');
}, {
offset: '70%'
});
在你的例子中,$(this)
指的是航路点对象,而不是特定的 dom 元素,这就是为什么你的代码 brakes.Console 记录 $(this)
,你会看到。
$('.team-member').waypoint(function (){
console.log( $(this) )
}, {
offset: '70%'
});