-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (30 loc) · 1018 Bytes
/
index.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
30
31
32
33
34
35
export default {
scrollTop: 0,
start: function() {
// Check if body is already freezed
const isFreezed = document.body.getAttribute("freezed");
if (isFreezed) return;
// Save scroll position
this.scrollTop =
window.scrollY ||
window.scrollTop ||
document.getElementsByTagName("html")[0].scrollTop;
document.body.style.position = "fixed";
document.body.style.overflow = "hidden";
document.body.style.top = `-${this.scrollTop}px`;
document.body.style.width = "100vw";
document.body.setAttribute("freezed", "");
},
stop: function() {
// Check if body is already unfreezed
const isFreezed = document.body.hasAttribute("freezed");
if (!isFreezed) return;
// Enable scrolling again
document.body.style.position = "relative";
document.body.style.top = null;
document.body.style.width = null;
document.body.style.overflow = null;
window.scrollTo(0, this.scrollTop);
document.body.removeAttribute("freezed");
}
};