different offset for jquery waypoint “up” event

前端 未结 1 1330
春和景丽
春和景丽 2020-12-12 23:23

i\'ll love to have 2 offsets in jquery waypoint. Currently there is only one, the same, for up and down scrolling.

I\'m using a \"down\" offset of 25%, and would lik

相关标签:
1条回答
  • 2020-12-13 00:11

    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%'
    });
    
    0 讨论(0)
提交回复
热议问题