Javascript code for obtaining the page height and the position of the scroll bar. For more information, see.
The Code is as follows:
Var Viewport = {
Top: function (){
Return window. pageYOffset
| Document.doc umentElement & document.doc umentElement. scrollTop
| Document. body. scrollTop;
},
Height: function (){
Return window. innerHeight
| Document.doc umentElement & document.doc umentElement. clientHeight
| Document. body. clientHeight;
},
Left: function (){
Return window. pageXOffset
| Document.doc umentElement & document.doc umentElement. scrollLeft
| Document. body. scrollLeft;
},
Width: function (){
Return window. innerWidth
| Document.doc umentElement & document.doc umentElement. clientWidth
| Document. body. clientWidth;
},
Right: function (){
Return Viewport. left () + Viewport. width ();
},
Bottom: function (){
Return Viewport. top () + Viewport. height ();
}
};
Center:
The Code is as follows:
Style. position = "absolute ";
Style. left = 50%;
Style. top = Viewport. Top () + Viewport. Height ()/2 + "px ";