Triggers events on various page elements as they are scrolled in to and out of view.
Bind events using the .on()
method:
// Pseudo-JavaScript
$('#element').scrollWatch(options).on(eventName, callback, thisArg);
// Example
$('#element').scrollWatch().on('scroll', function(event) {
console.log(event.visibility)
});
on(eventName, callback, [thisArg])
- Binds an event
scrollin
(event) — Triggered once, when the element is fully visible in the viewport.scrollout
(event) — Triggered once, when the none of the element is visible. Only triggers ifscrollin
has been called on the element.scroll
(event) — Triggered many times, every scroll event when the element is partially or fully visible.
A string that is either 'up'
or 'down'
indicating which direction the user is scrolling.
The original jQuery Event object.
A percent of the element that is visible, only useful for the scroll
event.
- Between
0
and-1
when the top of the element is bleeding out of view. - Between
0
and1
when the bottom of the element is bleeding out of view. - Is
1
on thescrollin
event - Is
0
on thescrollout
event
NOTE: Elements that are taller than the viewport would technically never have 100% visibility. However, visibility
will jump to 1
when both the top and bottom of the element are bleeding off the screen (effectively the element is taking up the entire vertical viewport space).
$('#element').scrollWatch(options)
watchOn
- The scrollable element to watch on. Can be a selector, DOM node or jQuery object. When using a custom element, it should haveoverflow: scroll
. Defaults towindow
.