jQuery航路点“向上"的不同偏移量事件 [英] different offset for jquery waypoint "up" event

查看:76
本文介绍了jQuery航路点“向上"的不同偏移量事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在jquery航点中具有2个偏移量. 当前,上下滚动只有一个.

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

我正在使用25%的向下"偏移量,并且希望使用"75%"的向上"偏移量. 因此,当块的顶部位于视口顶部的25%处并且滑行向下时, 下降"被触发.并且,当块的顶部位于视口顶部的75%处并且爬上坡时,就会触发向上".

I'm using a "down" offset of 25%, and would like an "up" offset of "75%". So when the top of a block is at 25% of the top of the viewport and the scolling is goin down, 'down' is triggered. And when the top of a block is at 75% of the top of the viewport and the scolling is goin up, 'up' is triggered.

任何人都已经为此滞后现象编写了代码?

Anyone has already writen code for this hysteresis ?

推荐答案

您可以通过创建两个航点来实现此目的,每个航点具有不同的偏移量,每个航点仅响应一个方向:

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

更新:如果您使用的是Waypoints 3.0的jQuery版本,则上述代码将不起作用,因为waypoint不再链接jQuery对象.相反,它返回创建的Waypoint实例的数组.如果您不希望保留该数组引用,则代码如下所示:

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

这篇关于jQuery航路点“向上"的不同偏移量事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆