最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Waypoints JS bottom-in-view, is there a top-in-view? - Stack Overflow

programmeradmin4浏览0评论

Im using waypoints js to detect when an element is in the viewport.

/

Is it possible to detect when the top of an element is at the bottom of the viewport?

Cheers

Ke

Im using waypoints js to detect when an element is in the viewport.

http://imakewebthings.com/jquery-waypoints/

https://github.com/imakewebthings/waypoints

Is it possible to detect when the top of an element is at the bottom of the viewport?

Cheers

Ke

Share Improve this question edited Oct 21, 2016 at 11:05 JJJ 33.2k20 gold badges94 silver badges103 bronze badges asked Aug 30, 2014 at 18:41 Ke.Ke. 2,5868 gold badges40 silver badges82 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 21

Nobody has given a correct answer yet, so here is mine.

As you already know, the Waypoint plugin has an offset option. This option triggers the handler function after either the top or bottom of your element has passed either the top or bottom of the viewport.

The offset value as a percentage represents the height of the viewport where you want the function to fire - 0% being right at the top, 50% in the middle, and 100% right at the bottom.

To fire your handler function when the top of your element immediately comes into view, you will need to use 100%, like this:

$('.sections').waypoint({
    handler: function(direction) {
        // do stuff
    },
    offset: '100%'
});
发布评论

评论列表(0)

  1. 暂无评论