Home > Web Front-end > JS Tutorial > Use js or jq to set scroll bars to achieve method sharing

Use js or jq to set scroll bars to achieve method sharing

小云云
Release: 2018-03-14 17:35:32
Original
1932 people have browsed it


js native method scrollTojs native settings <span style="font-size: 14px;">x</span> axis and <span style="font-size: 14px;"> There is only one method for the y</span> axis. First get the <span style="font-size: 14px;">dom</span> object, and then set the position,

dom.scrollTo(x,y); //x为水平方向的滚动条位置,y为垂直方向的滚动条位置
Copy after login

If you only want to set the scroll bar position of the y axis, you first need to obtain the current scroll bar position of the x axis, and then set the y axis , such as:

dom.scrollTo(dom.scrollLeft, 100); 
//设置y轴滚动一百像素dom.scrollTo(100, dom.scrollTop);
//设置x轴滚动一百像素
Copy after login

jq method

The related method of jq is, set the x-axis

$("#id").scrollTop(100);  
//设置y轴滚动条位置为滚动100像素的位置$("#id").scrollTop(); 
//返回当前滚动条y轴的滚动的位置
Copy after login

set the y-axis

$("#id").scrollLeft(100);  
//设置x轴滚动条位置为滚动100像素的位置$("#id").scrollLeftp();
 //返回当前滚动条x轴的滚动的位置
Copy after login

Related recommendations:

How to automatically load more content when the scroll bar slides to the bottom

How to modify the scroll bar style

How Use jQuery to eliminate scroll bars on web pages

The above is the detailed content of Use js or jq to set scroll bars to achieve method sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template