Home>Article>Web Front-end> How to set scroll bar position in javascript
##The operating environment of this tutorial: windows7 system, javascript version 1.8.5, DELL G3 computer.How to set the scroll bar position in javascript: 1. Put the vertical scroll bar at the top, the code is [(window.scrollTo(0,0);]]; 2. Put the vertical scroll bar at the bottom, the code is [window .scrollTo(0,document.body.scrollHeight)】.
How to set the scroll bar position in javascript:
JS controls the position of the scroll bar:window.scrollTo(x,y);The vertical scroll bar is on top (window.scrollTo(0, 0); The vertical scroll bar is set to the bottom window.scrollTo(0,document.body.scrollHeight) JS controls the TextArea scroll bar to automatically scroll to the bottom
document.getElementByIdx_x('textarea').scrollTop = document.getElementByIdx_x('textarea').scrollHeightGet the distance from the top of the scroll bar
function getScrollTop(){ var scrollTop=0; if(document.documentElement&&document.documentElement.scrollTop){ scrollTop=document.documentElement.scrollTop; }else if(document.body){ scrollTop=document.body.scrollTop; } return scrollTop; }
Related free learning recommendations:
The above is the detailed content of How to set scroll bar position in javascript. For more information, please follow other related articles on the PHP Chinese website!