Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 830
Ke. Avatar asked Aug 30 '14 18:08

Ke.


1 Answers

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%'
});
like image 74
TheCarver Avatar answered Oct 06 '22 23:10

TheCarver