jQuery scroll Event

Beginner
7 min read
Updated: Oct 2026
5 examples
Live preview

What Is scroll?

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
NeedUse
Listen on a box$("#el").on("scroll", fn)
Listen on the page$(window).on("scroll", fn)
Read position$("#el").scrollTop()
Fire handlers now$("#el").trigger("scroll")
Heavy workThrottle / debounce inside the handler
Legacy shorthand.scroll() ⚠

How to Use scroll

Bind on the element that actually scrolls, keep the handler light, and throttle expensive work.

  1. Attach with $("#el").on("scroll", handler) or $(window).on("scroll", handler).
  2. Read position with .scrollTop() / .scrollLeft() inside the handler.
  3. Throttle or debounce DOM-heavy work — scroll can fire dozens of times per second.
  4. Call .trigger("scroll") when you need the same logic without a real scroll.
  5. Remove with .off("scroll", handler) when cleaning up.
PieceRequired?Role
TargetYeswindow or a scrollable element
handlerYesfunction(event)
eventDataOptionalExtra data as event.data
ThrottleRecommendedLimit 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

Cheat Sheet

Keep these facts handy while wiring scroll-aware UI.

TopicDetail
Bind$("#el").on("scroll", handler)
Unbind$("#el").off("scroll" [, handler])
Trigger$("#el").trigger("scroll")
Signaturefunction(event)
WhenScroll position changes (any cause)
Since.on() form 1.7 · trigger 1.0
Targetswindow, frames, overflow elements
Position.scrollTop() / .scrollLeft()

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.

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. ");
});
Try It Yourself

How It Works

  1. Bind. .on("scroll") on #target listens for position changes.
  2. Scroll. Wheel, scrollbar, keys, or touch all fire the same event.
  3. Append. Each firing adds another message fragment.
  4. 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");
});
Try It Yourself

How It Works

  1. Bind. A scroll handler is attached to #target.
  2. Click. The button calls .trigger("scroll").
  3. Run. Bound handlers execute as if the user scrolled.
  4. Use. Handy for tests and syncing UI after .scrollTop().

Example 3 — Window (Page) Scroll

Official pattern: react when the page (window) is scrolled.

jQuery
$(window).on("scroll", function () {
  $("#msg").text("Scroll happened!");
});
Try It Yourself

How It Works

  1. Target. Page scroll is delivered to window.
  2. Bind. $(window).on("scroll", fn) listens for it.
  3. Update. The handler writes a short status message.
  4. Tip. Keep window scroll handlers light — they fire often.

Example 4 — Read scrollTop

Use the handler to report how far the element has scrolled.

jQuery
$("#target").on("scroll", function () {
  var top = $(this).scrollTop();
  $("#pct").text("scrollTop: " + top + "px");
});
Try It Yourself

How It Works

  1. Listen. The handler runs whenever position changes.
  2. Measure. $(this).scrollTop() reads the current offset.
  3. Display. The value is written to #pct.
  4. 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);
  }
});
Try It Yourself

How It Works

  1. Count raw. Every scroll event increments raw.
  2. Gate. Expensive work runs only if 150 ms have passed.
  3. Compare. Throttled runs stay far below raw event count.
  4. Use. Prefer this pattern for progress UI and sticky checks.

Edge Cases & Pitfalls

Check these before shipping scroll-sensitive UI.

target

Bind the element that scrolls

Page scroll → window. Panel scroll → that overflow element. Wrong target means silence.

cost

Heavy work on every scroll hurts

Scroll can fire dozens of times per second. Throttle or debounce DOM measurements and layout work.

vs

Not the same as .scrollTop()

scroll is an event. .scrollTop() gets or sets position. Use both together when you need live progress.

deprecated

Prefer .on() over .scroll()

.scroll(handler) is deprecated since 3.3. New code should use .on("scroll").

Browser Support

The scroll event is a native browser event. Prefer .on("scroll", …) (jQuery 1.7+). Trigger with .trigger("scroll") since 1.0.

✓ Stable · jQuery 1.7+

jQuery scroll

Works in every browser that runs your loaded jQuery version. Applies to window and scrollable overflow elements.

100% Browser event
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
scroll Universal

Bottom line: Safe for everyday apps. Bind the element that scrolls, throttle expensive work, and prefer .on('scroll') over deprecated .scroll().

Performance Notes

ApproachCostBest for
Light log / scrollTop readCheapDebugging, simple labels
Throttled progress / sticky checkCheap–moderateLive UI while scrolling
Heavy DOM work every scrollExpensiveAvoid — throttle or debounce

Scroll handlers are fine when they stay light. Update visuals on a throttle; do expensive work after scrolling settles.

Key Takeaways

  • Role: scroll position changed — update progress, sticky UI, lazy checks.
  • 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.

Next: .scroll() method

See the deprecated shorthand and how to migrate to .on("scroll").

.scroll() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful