Содержание:
.scroll( handler )Возвращает: jQuery
Описание: Устанавливает обработчик "прокрутки" элементов документа, либо, запускает это событие.
-
Добавлен в версии: 1.0.scroll( handler )
-
handlerA function to execute each time the event is triggered.
-
-
Добавлен в версии: 1.4.3.scroll( [eventData ], handler )
-
eventDataТип: AnythingAn object containing data that will be passed to the event handler.
-
handlerA function to execute each time the event is triggered.
-
-
Добавлен в версии: 1.0.scroll()
- This signature does not accept any arguments.
This method is a shortcut for .on( "scroll", handler )
in the first and second variations, and .trigger( "scroll" )
in the third.
The scroll
event is sent to an element when the user scrolls to a different place in the element. It applies to window
objects, but also to scrollable frames and elements with the overflow
CSS property set to scroll
(or auto
when the element's explicit height or width is less than the height or width of its contents).
For example, consider the HTML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
|
The style definition is present to make the target element small enough to be scrollable:

The scroll
event handler can be bound to this element:
1
2
3
|
|
Now when the user scrolls the text up or down, one or more messages are appended to <div id="log"></div>
:
Handler for .scroll() called.
To trigger the event manually, apply .scroll()
without an argument:
1
2
3
|
|
After this code executes, clicks on Trigger the handler will also append the message.
A scroll
event is sent whenever the element's scroll position changes, regardless of the cause. A mouse click or drag on the scroll bar, dragging inside the element, pressing the arrow keys, or using the mouse's scroll wheel could cause this event.
Дополнительные замечания:
-
As the
.scroll()
method is just a shorthand for.on( "scroll", handler )
, detaching is possible using.off( "scroll" )
.