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").
Remember
$("#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
Bind on the element that actually scrolls, keep the handler light, and throttle expensive work.
Attach with $("#el").on("scroll", handler) or $(window).on("scroll", handler).
Read position with .scrollTop() / .scrollLeft() inside the handler.
Throttle or debounce DOM-heavy work — scroll can fire dozens of times per second.
Call .trigger("scroll") when you need the same logic without a real scroll.
Remove with .off("scroll", handler) when cleaning up.
Piece
Required?
Role
Target
Yes
window or a scrollable element
handler
Yes
function(event)
eventData
Optional
Extra data as event.data
Throttle
Recommended
Limit how often expensive work runs
Pseudocode
Pseudocode
bind scroll on target with handler(event)
when scroll position changes (wheel, bar, keys, touch):
fire scroll on target
for each registered handler:
call handler(event)
// may fire many times during one gesture
when your code needs the same logic:
trigger scroll on target
for expensive work:
on each scroll:
if enough time passed since last run:
update UI / measure
else:
skip this tick
Reference
Cheat Sheet
Keep these facts handy while wiring scroll-aware UI.
Topic
Detail
Bind
$("#el").on("scroll", handler)
Unbind
$("#el").off("scroll" [, handler])
Trigger
$("#el").trigger("scroll")
Signature
function(event)
When
Scroll position changes (any cause)
Since
.on() form 1.7 · trigger 1.0
Targets
window, frames, overflow elements
Position
.scrollTop() / .scrollLeft()
Try it
Live Preview
Scroll the box (or click Trigger) and watch the scroll handler update the log.
Tip: scroll inside the box below to fire real scroll events, or use Trigger.
Result
Ready — scroll the box or click Run.
Code
jQuery Examples
Short, copy-ready snippets. Scroll the preview, or use Try It Yourself for a live editor.
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.
Count. Do not assume a fixed number of calls per gesture.
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");
});
Listen. The handler runs whenever position changes.
Measure.$(this).scrollTop() reads the current offset.
Display. The value is written to #pct.
Build on it. Same idea powers reading progress bars.
Example 5 — Throttle Expensive Work
Run heavy work at most every 150 ms while scrolling stays active.
jQuery
var raw = 0, th = 0, last = 0;
$("#target").on("scroll", function () {
raw++;
$("#raw").text(raw);
var now = Date.now();
if (now - last >= 150) {
last = now;
th++;
$("#th").text(th);
}
});
Bind:.on("scroll", fn) on window or the overflow element.
Throttle: expensive work should not run on every raw event.
Trigger: use .trigger("scroll") to reuse handlers without scrolling.
One line:scroll reports position changes — bind with .on() and throttle heavy work.
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.