The scroll event is sent when the user scrolls to a different place in an element. Bind it with .on("scroll", handler) (since jQuery 1.7). It applies to window, scrollable frames, and overflow elements. Trigger it with .trigger("scroll").
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$("#target").on("scroll", function () {
// scroll position changed
});
$(window).on("scroll", function () {
// page scrolled
});
$("#target").trigger("scroll"); // fire handlers programmatically
// Scroll fires often — throttle / debounce heavy work
Call
What it does
Scroll
Learn jQuery scroll: bind .on(\
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Attach with $("#el").on("scroll", handler) or $(window).on("scroll", handler).
Step 2
Read position with .scrollTop() / .scrollLeft() inside the handler.
Step 3
Throttle or debounce DOM-heavy work — scroll can fire dozens of times per second.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
jQuery Examples
Example 1 — Append to #log
Official pattern: append a short message each time #target scrolls.
jQuery
$("#target").on("scroll", function () {
$("#log").append("Handler for scroll called. ");
});
Scroll #target →
#log gains "Handler for scroll called. "
May append many times during one gesture
How It Works
Bind..on("scroll") on #target listens for position changes.
Scroll. Wheel, scrollbar, keys, or touch all fire the same event.
Append. Each firing adds another message fragment.
Example 2 — Trigger from a Button
Official demo: click #other to fire .trigger("scroll") on #target.
jQuery
$("#target").on("scroll", function () {
$("#log").text("Handler for scroll called.");
});
$("#other").on("click", function () {
$("#target").trigger("scroll");
});
Scroll the page →
#msg shows "Scroll happened!"
Use for sticky headers, back-to-top, progress
How It Works
Target. Page scroll is delivered to window.
Bind.$(window).on("scroll", fn) listens for it.
Update. The handler writes a short status message.
Frequently Asked Questions
The scroll event is sent to an element when the user scrolls to a different place in that element. Bind with .on("scroll", handler) since jQuery 1.7. It applies to window, scrollable frames, and elements with overflow:scroll or overflow:auto when content overflows.
Use $(window).on("scroll", fn) for page-level scroll — back-to-top buttons, sticky headers, and reading progress. Bind on a specific element like $("#panel").on("scroll", fn) when only that container scrolls. The event target must be the element whose scrollTop or scrollLeft actually changes.
Call $("#target").trigger("scroll") since jQuery 1.0. Bound scroll handlers on that element run as if the user scrolled — useful for testing or syncing UI after you change position with .scrollTop().
Throttle for visual updates that should stay responsive while scrolling — progress bars and sticky checks often run every 100–150 ms. Debounce when you only need the final position after scrolling stops. Scroll can fire dozens of times per second; never run heavy DOM work on every raw event.
Scroll fires when content position changes inside a scrollable element — the viewport size stays the same. Resize fires on window when the browser viewport width or height changes. Bind scroll for reading position; bind resize for layout reflow.
They target the same browser scroll event. .scroll(handler) is the legacy shorthand deprecated since jQuery 3.3; .on("scroll", handler) is the modern replacement since 1.7. .scroll() still works in jQuery 3.x but should not be used in new code. Do not confuse it with .scrollTop(), which gets or sets scroll position.