-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen.js
29 lines (29 loc) · 873 Bytes
/
screen.js
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
helper = {
Screen: {
isInViewport: function (elem) {
var distance = elem.getBoundingClientRect();
return (
distance.top >= 0 &&
distance.left >= 0 &&
distance.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
distance.right <= (window.innerWidth || document.documentElement.clientWidth)
);
},
scrollTop: function (cb) {
var intervalId = setInterval(function () {
if (!cb || typeof cb !== 'function') return;
if (window.pageYOffset === 0) {
clearInterval(intervalId);
cb && cb();
}
window.scrollTo(0, window.pageYOffset - 50);
}, 16.66);
},
scrollToBottom: function () {
window.scrollTo(0, document.body.scrollHeight);
},
scrollToElem: function (elem) {
elem.scrollIntoView(true);
}
}
};