jQuery scroll Event

Beginner
5 min read
Updated: Nov 2026
3 examples
Browser Events

Definition

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
CallWhat it does
ScrollLearn jQuery scroll: bind .on(\

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Attach with $("#el").on("scroll", handler) or $(window).on("scroll", handler).
Step 2Read position with .scrollTop() / .scrollLeft() inside the handler.
Step 3Throttle or debounce DOM-heavy work — scroll can fire dozens of times per second.

Return Value

Return ValueDescription
jQuery objectMost 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. ");
});
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.

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.

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.

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() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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