different offset for jquery waypoint “up” event

狂风中的少年 提交于 2019-11-28 16:44:30

You can do this by creating two waypoints, each with different offsets, each only responding to one direction:

$('.thing').waypoint(function(direction) {
  if (direction === 'down') {
    // Do stuff
  }
}, {
  offset: '25%'
}).waypoint(function(direction) {
  if (direction === 'up') {
    // Do stuff
  }
}, {
  offset: '75%'
});

Update: If you're using the jQuery build of Waypoints 3.0, the above code will not work because waypoint no longer chains the jQuery Object. It instead returns an array of the Waypoint instances created. If you're not interested in keeping that array reference around, the code would look like this:

var $things = $('.thing');

$things.waypoint(function(direction) {
  if (direction === 'down') {
    // Do stuff
  }
}, {
  offset: '25%'
});

$things.waypoint(function(direction) {
  if (direction === 'up') {
    // Do stuff
  }
}, {
  offset: '75%'
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!