English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery scroll() Method

jQuery Events

The scroll() method triggers the scroll event or attaches a function to be executed when the scroll event occurs.

A scroll event occurs when the scrollbar of a scrollable element is scrolled.

The scroll event applies to all scrollable elements and window objects (browser window).

Syntax:

Trigger the scroll event of the selected element:

$(selector).scroll()

Attach the function to the scroll event:

$(selector).scroll(function)

Example

Calculate the number of times scrolling is used for the window:

$(window).scroll(function() { 
  $("span").text(x++); 
});
Test and see‹/›

Calculate the number of times scrolling is used for the DIV element:

$("div").scroll(function() { 
  $("span").text(x++); 
});
Test and see‹/›

Parameter Value

ParametersDescription
functionFunction executed each time the scroll event triggers

jQuery Events