jQuery scroll() method
Thescroll() method is used to trigger the scroll event or attach a function to run when scrolling occurs.
The scroll event occurs when a scrollbar is used for an element. The event is triggered when the user moves the scrollbar up or down. We can use the CSSoverflowproperty for creating a scrollbar. The scroll event fires for window objects or for all scrollable elements.
We can either simply use the scroll() method or can add a function to the scroll event. The syntax of using the scroll() method is given as follows -
Trigger the event for the selected elements
Attach a function
Theselector in the above syntax is the selected element. The parameter function mentioned in the above syntax is optional. It is a function to execute when the scroll event occurs. The attached function performs a specific task on scrolling.
Let's see an illustration of using the scroll()method.
It is a simple example of using the scroll() method. Here, there is a paragraph element with id = "para" on which we are applying the scroll() method. On scrolling the paragraph, the function attached to the scroll() method will trigger and will change the color and the background color of the corresponding paragraph. Here, we are using the optional parameter of the scroll()method.Test it Now
After scrolling the bordered text on the screen, we will get the following output -
C看美女app 最新章节(作者 苍山小菜农) E道阅读网,红高粱 下载全文免费阅读 红高粱 下载 E道阅读网,妹汁第三部全文免费阅读 妹汁第三部 E道阅读网