Waypoint jQuery - 上下滚动的2个不同偏移量

时间:2012-11-16 16:48:32

标签: jquery

为什么它无法正常工作? 我需要创建两个不同的偏移量。向下滚动小和向下滚动。 此代码无效。

// 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' });   

1 个答案:

答案 0 :(得分:0)

您可以使用两个航点来完成此操作:

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

有关详细信息,请查看主人自己回答的主题:

different offset for jquery waypoint "up" event