Home > Article > Web Front-end > Use js or jq to set scroll bars to achieve method sharing
<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为垂直方向的滚动条位置
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轴滚动一百像素
The related method of jq is, set the x-axis
$("#id").scrollTop(100); //设置y轴滚动条位置为滚动100像素的位置$("#id").scrollTop(); //返回当前滚动条y轴的滚动的位置
set the y-axis
$("#id").scrollLeft(100); //设置x轴滚动条位置为滚动100像素的位置$("#id").scrollLeftp(); //返回当前滚动条x轴的滚动的位置
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!