This module will trigger a callback as your window is scrolling and return an element position.
A work-in-progress JS module.
Built by: Mario Lo
yarn add scroll-callback
import { scrollCallback, scrollCallbackWithElement, callbackAtElement } from 'scroll-callback';
(() => {
scrollCallback(scrollAction, 1000);
scrollCallbackWithElement(scrollAction, 1000, 'profile-container');
callbackAtElement(scrollAction, 1500, 'profile-container');
})();
This will add a scroll event listener to your window object
scrollCallback
This will trigger the callback while the page is scrolling.
scrollCallbackWithElement
This will trigger the callback and return an element position object while the page is scrolling.
callbackAtElement
This will trigger the callback at the element. The callback will only be triggered once.
Returns the element in callback
scrollCallback(callback, waitDuration);
scrollCallbackWithElement(callback, waitDuration, elementId);
callbackAtElement(callback, waitDuration, elementId);
Parameter Name | Type | Required | Default Value | Description |
---|---|---|---|---|
callback | function | true | null | A function to be called on scroll |
waitDuration | number | false | 50 | Wait duration in between callback |
elementId | string | false | null | The id of the element we want the position of |
callback
type: function
This function will be called as the window is scrolling.
waitDuration
type: number
This is a wait time in milli-seconds. This sets the wait time in a setTimeout call to delay the scroll listener.
elementId
type: string
This is an element id in the DOM. If supplied, the element position will be returned to the callback. This calls getBoundingClientRect()
on the element.
-
Return an element position in callbackimplemented in version 0.0.37 - Remove scroll event listener Currently only implemented in
callbackAtElement
Please message [email protected] for feature requests.
Please message [email protected] to report bugs.