2017-01-22 75 views
0

在我的代码不能正常工作$(本)在jQuery的航点功能,无需$(这)一切正常jQuery的航点插件不能正常工作

<script> 
    $('.team-member').waypoint(function(){ 
     $(this).addClass('bgr'); 
    }, { 
     offset: '70%' 
    }); 
</script> 

сss

.bgr { 
    background: red; 
} 

任何想法?

回答

0

工作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元素这就是为什么你的代码刹车。控制台日志$(this),你会看到。

$('.team-member').waypoint(function(){ 
    console.log($(this)) 
}, { 
    offset: '70%' 
}); 
+0

谢谢你。它的工作原理。你能解释一下,为什么我有这个问题? –

+0

我刚刚编辑我的答案,请参阅 – Devsullo