jQuery scroll() function triggers when the element is scrolled. This method attaches a handler, which executes when the scroll event is fired. A scroll event fires for all elements which are scrollable and it also fires for window objects.

jQuery scroll()

The syntax for using jQuery scroll() function is:

This signature is used without any arguments. This method is a shortcut for .trigger( "scroll" ).

The handler is a function, which is executed when the element gets scrolled. This method is a shortcut for .on( "scroll", handler ).

jQuery scroll example

Following example demonstrates jQuery scroll() function usage.

In this example, you can see that the scroll() method is triggered when you scroll in the <div> element. The handler attached to the scroll() method executes with each scroll event displays the count below the <div> element.

jQuery scroll demo

You can try it yourself by scrolling in the below div section.

By admin

Leave a Reply