1

为什么它不能正常工作?我需要创建两个不同的偏移量。向上滚动小,向下滚动最大。这段代码不能很好地工作。

// The same for all waypoints

$('body').delegate('section > article', 'waypoint.reached', function(event, direction) {
    var $active = $(this);

    if (direction === "up") {
        $active = $active.prev();
        $('section > article').waypoint({ offset: '10%' });
    }
    if (!$active.length) $active = $active.end();

            if (direction === "down") {

        $('section > article').waypoint({ offset: '60%' });
    }


    $('.link-active').removeClass('link-active');
    $('a[href=#'+$active.attr('id')+']').addClass('link-active');
});

// Register each section as a waypoint.


$('section > article#p1').waypoint({ offset: '28%' });
$('section > article').waypoint({ offset: '0' });   
4

1 回答 1

0

您可以通过使用两个航点来做到这一点:

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

有关更多信息,请查看大师本人回答的主题:

jquery航点“向上”事件的不同偏移量

于 2014-05-10T18:56:10.773 回答