-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUntitled-1.js
85 lines (74 loc) · 2.99 KB
/
Untitled-1.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const disableBodyScroll = bodyScrollLock.disableBodyScroll,
enableBodyScroll = bodyScrollLock.enableBodyScroll;
var config = {
boards: []
},
d = {
num: void 0,
board: void 0,
dialog: void 0,
main: document.getElementsByTagName("main")[0],
isBgBlocked: !1,
isLandscape: void 0
};
function configurate() {
let e = {
isTouch: "ontouchstart" in window || navigator.maxTouchPoints,
isLandscape: window.innerWidth / window.innerHeight > 1,
isAnimate: !1,
scrollNow: window.config.scrollNow || 0,
delta: 0,
boards: [],
animation: 500,
animStart: 0
},
n = Array.from(document.getElementsByClassName("dialog"));
function o(e, n) {
let o = window.config.boards.hasOwnProperty(n) && window.config.boards[n].current || 0;
this.el = e, this.w = function (e) {
let n = Array.from(e.children),
o = window.innerWidth;
return n.forEach(function (e) {
o -= e.offsetWidth
}), o
}(e), this.prev = o, this.current = o
}
return n.unshift(document.getElementsByTagName("main")[0]), n.forEach(function (n, i) {
e.boards.push(new o(n.children[0], i))
}), e
}
function init() {
!(config = configurate()).isTouch && config.isLandscape ? (document.body.classList.add("notouch"), attachScroll(), config.isAnimate = !0) : (detachScroll(), document.body.classList.remove("notouch"), config.isAnimate = !1, config.boards.forEach(function (e) {
e.el.style = "", e.prev = 0, e.current = 0
})), config.isLandscape && d.isBgBlocked && config.isLandscape != d.isLandscape && (enableBodyScroll(d.dialog), d.isBgBlocked = !1)
}
function attachScroll() {
"onwheel" in document ? window.addEventListener("wheel", onWheel) : "onmousewheel" in document ? window.addEventListener("mousewheel", onWheel) : window.addEventListener("MozMousePixelScroll", onWheel)
}
function detachScroll() {
"onwheel" in document ? window.removeEventListener("wheel", onWheel) : "onmousewheel" in document ? window.removeEventListener("mousewheel", onWheel) : window.removeEventListener("MozMousePixelScroll", onWheel)
}
function onWheel(e) {
var n = (e = e || window.event).deltaY || e.detail || -e.wheelDelta;
n *= 1 === e.deltaMode ? 16 : 1, config.delta = -.5 * n
}
function animate() {
let e = performance.now(),
n = config.animation + config.animStart <= e;
config.isAnimate && n && drawFrame(), requestAnimationFrame(animate)
}
function drawFrame() {
let e = config.boards[config.scrollNow];
e.current > 0 ? e.current = .9 * e.current + config.delta / 4 : e.current < e.w ? e.current = e.w - .9 * (e.w - e.current) + config.delta / 4 : e.current = e.prev + config.delta, config.delta *= .9, e.el.style = "transform: translate3D(" + e.current + "px, 0, 0 );", e.prev = e.current
}
function setVh() {
let e = .01 * window.innerHeight;
document.documentElement.style.setProperty("--vh", `${e}px`)
}
document.addEventListener("DOMContentLoaded", function () {
setVh()
}), window.addEventListener("load", function () {
init()
}), window.addEventListener("resize", function () {
init(), setVh()
}), init(), animate();