forked from maksrom/javascript-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumentScroll.js
More file actions
executable file
·39 lines (30 loc) · 1.15 KB
/
documentScroll.js
File metadata and controls
executable file
·39 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Объект с информацией о прокрутке в документе
* @return {object}
* top: сколько пикселей прокручено сверху, верхняя граница видимой части
* bottom: top + высота окна, то есть нижняя граница видимой части пикселей низ,
* height: полная высота страницы
*/
function getDocumentScroll() {
return {
top: getDocumentScrollTop(),
bottom: getDocumentScrollBottom(),
height: getDocumentScrollHeight()
};
}
function getDocumentScrollTop() {
var html = document.documentElement;
var body = document.body;
var scrollTop = html.scrollTop || body && body.scrollTop || 0;
scrollTop -= html.clientTop; // IE<8
return scrollTop;
}
function getDocumentScrollHeight() {
var scrollHeight = document.documentElement.scrollHeight;
var clientHeight = document.documentElement.clientHeight;
scrollHeight = Math.max(scrollHeight, clientHeight);
return scrollHeight;
}
function getDocumentScrollBottom() {
return getDocumentScrollTop() + document.documentElement.clientHeight;
}