Documentation / @andrew_l/dom / isScrolledToDown
Function: isScrolledToDown() ​
isScrolledToDown(
target
,threshold
):boolean
Determines if the specified element or the document/window is scrolled near the bottom.
This function checks if the scroll position has reached the bottom of the target element or window within a specified threshold. It is commonly used for implementing "infinite scroll" or detecting when a user has scrolled to the bottom of a page or container.
Parameters ​
target ​
The target element, document, or window to check the scroll position. Can be an HTMLElement
, Document
, or Window
.
Window
| Document
| HTMLElement
threshold ​
number
= 10
The threshold (in pixels) below which the target is considered "scrolled to the bottom." Default is 10
, meaning the target is considered scrolled to the bottom if it is within 10px of the bottom.
Returns ​
boolean
true
if the target is scrolled near the bottom within the given threshold, otherwise false
.
Examples ​
// Check if the window is scrolled near the bottom
isScrolledToDown(window, 20); // Returns true if within 20px of the bottom of the window.
// Check if a specific container is scrolled near the bottom
const container = document.getElementById('myContainer');
isScrolledToDown(container, 50); // Returns true if within 50px of the bottom of the container.