Home>Article>Web Front-end> How to modify the scroll bar position in jquery

How to modify the scroll bar position in jquery

青灯夜游
青灯夜游 Original
2022-05-23 14:17:36 4938browse

Modification method: 1. Use scrollLeft() to set the position of the horizontal scroll bar, the syntax is "$("scroll bar element").scrollLeft(position value)"; 2. Use scrollTop() to set the position of the horizontal scroll bar. Set the vertical scroll bar position, the syntax is "$("scroll bar element").scrollTop(position value)".

How to modify the scroll bar position in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

jquery provides two methods to directly modify the scroll bar position

  • scrollLeft()

  • scrollTop()

1. Use scrollLeft()

scrollLeft() to set the offset of the matching element relative to the left side of the scroll bar, that is, the position of the horizontal scroll bar .

The horizontal position of the scroll bar refers to the number of pixels scrolled from its left side. When the scroll bar is at the far left, the position is 0.

Example:

      
The longest word in the english dictionary is: pneumonoultramicroscopicsilicovolcanoconiosis.

How to modify the scroll bar position in jquery

2. Use scrollTop()

scrollTop() to set The offset of the matched element relative to the top of the scroll bar, i.e. the position of the vertical scroll bar.

Example:

      
This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.

How to modify the scroll bar position in jquery

[Recommended learning:jQuery video tutorial,web front-end video

The above is the detailed content of How to modify the scroll bar position 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