Web development often encounters the need to get the browser's scroll bar and the top and bottom of the distance, and then do the appropriate processing action. The following author on how to get through JS browser scroll bar from the top of the browser and the bottom of the height to do a share, this is compatible with IE and Firefox.
The first two definitions we need to know are:
The height of the scroll bar from the top of the browser = window scroll bar height;
The height of the scroll bar from the bottom of the browser = The actual height of the document (page) content-the height of the scroll bar from the top of the browser-the height of the window's viewable range;
Well, with this definition, let's take a look at how to get the various heights, and here's an example.
Gets the height of the window's viewable range
Function getclientheight () { var clientHeight=0; if (document.body.clientheight&& Document.documentElement.clientHeight) { var clientheight= (document.body.clientheight<document.documentelement.clientheight)? document.body.clientheight:document.documentelement.clientheight; }else{ var clientheight= (document.body.clientheight> Document.documentElement.clientHeight)?document.body.clientheight:document.documentelement.clientheight; } return clientHeight; }
Get window scroll bar height
function Getscrolltop () {var scrolltop=0; if (document.documentelement&&document.documentelement.scrolltop) {Scrolltop=document.documentelement.s Crolltop; }else if (document.body) {scrolltop=document.body.scrolltop; return scrolltop; }
Get the actual height of the document content
function Getscrollheight () {return Math.max (document.body.scrollheight,document.documentelement.scrollheight); }
The following is a specific sample code, note here in order to demonstrate the effect of using a fixed suspension box effect, under IE fixed suspension effect and the above code some conflict does not work, here do not delve into, readers can see under the Firefox effect, the code itself is no problem.