.scroll() is jQuery’s legacy shorthand (since 1.0) for binding or triggering the browser scroll event on window or a scrollable element. It is deprecated since 3.3 but still works in jQuery 3.x. Prefer .on("scroll") / .trigger("scroll").
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// Deprecated (since 3.3) — still works in jQuery 3.x
$("#target").scroll(function () {
// scroll position changed
});
$("#target").scroll(); // trigger
// Modern replacements
$("#target").on("scroll", handler);
$("#target").trigger("scroll");
Call
What it does
Target
window or a scrollable element
handler
function(event)
eventData
Extra data as event.data
Throttle
Limit how often expensive work runs
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Bind with $("#el").scroll(handler) (legacy) or .on("scroll", handler) (preferred).
Click #run → .scroll() fires the event
Bound handler runs without a real scroll
How It Works
Bind. The handler is registered first.
Click. No-arg .scroll() triggers the event.
Run. Bound handlers execute immediately.
Frequently Asked Questions
The .scroll() method has two roles. With a handler — .scroll(handler) or .scroll(eventData, handler) — it binds a function that runs when the user scrolls a matched element. Bind on $(window) for page scroll or on an overflow element for container scroll. With no arguments — .scroll() — it triggers the scroll event. Both forms exist since jQuery 1.0; binding is deprecated since 3.3.
Deprecated, not removed. Binding signatures are deprecated since jQuery 3.3 — use .on("scroll", handler) instead. Unlike .error(), which was removed in jQuery 3.0, .scroll() still works in jQuery 3.x. Prefer .trigger("scroll") over no-arg .scroll() for clarity.
.scroll(handler) registers a callback and does not fire immediately. .scroll() with no arguments triggers the scroll event on each matched element — the same as .trigger("scroll"). Bind on the element whose scrollTop or scrollLeft actually changes.
.scroll() is an event shorthand — it binds or triggers the scroll event. .scrollTop() gets or sets the vertical scroll position. They are not interchangeable: binding .scroll() does not move the page, and .scrollTop(100) does not register a listener.
Replace .scroll(fn) with .on("scroll", fn). Replace .scroll(data, fn) with .on("scroll", data, fn). Replace no-arg .scroll() with .trigger("scroll"). Cleanup with .off("scroll"). Under the hood, .scroll(handler) already delegates to .on("scroll").
Yes. Scroll can fire dozens of times per second. Wrap progress bars and sticky checks in throttle (or debounce when you only need the final position), whether you use legacy .scroll(fn) or modern .on("scroll", fn).