Home>Article>Web Front-end> How to determine the direction of scroll event in jquery

How to determine the direction of scroll event in jquery

coldplay.xixi
coldplay.xixi Original
2020-11-23 10:06:04 1956browse

Jquery method to determine the direction of the scroll event: use the [scrollTop()] method to set or return the vertical scroll bar position of the selected element, the syntax is [$(selector).scrollTop(position)].

How to determine the direction of scroll event in jquery

The operating environment of this tutorial: Windows 7 system, jquery version 3.2.1. This method is suitable for all brands of computers.

jquery's method of determining the direction of a scrolling event:

In jQuery, you can use the scrollTop() method to determine the direction of a scrolling event. The scrollTop() method is used to set or Returns the vertical scroll bar position of the selected element. Using this method, we can determine the scroll direction.

jQuery scrollTop()Method

scrollTop() method sets or returns the vertical scroll bar position of the selected element.

Tip: When the scroll bar is at the top, the position is 0.

Syntax:

$(selector).scrollTop(position)

Parameters: This method accepts a single parameter position, which is optional. It is used to specify the vertical scroll bar position in pixels.

Return value: Returns the vertical position of the scroll bar of the selected element.

Example:

     

Related free learning recommendations:JavaScript(Video)

The above is the detailed content of How to determine the direction of scroll event in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn