JQuery waypoints using multiple classes

删除回忆录丶 提交于 2019-12-05 02:57:56

If I understand you correctly try this. It should iterate through each .waypoint element and add individual waypoints to each one that add the .on class as you scroll past them.

$('.staffmember').each(function() {
  $(this).waypoint(function() {
    $(this).addClass('on');
  });
});
Kate

I think your problem was that you were adding the "on" class to ALL matching elements (jQuery('.staffmember')), instead of just to the triggering element. Waypoints already does the iteration for you, as imakewebthings points out.

So, your original jQuery should be:

$('.staffmember').waypoint(function(direction) {
  jQuery(this).addClass('on').next();
});

That should do the trick without the each.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!