-
Notifications
You must be signed in to change notification settings - Fork 100
/
Stage.js
98 lines (70 loc) · 2.54 KB
/
Stage.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
86
87
88
89
90
91
92
93
94
95
96
97
98
import { TweenMax as TM } from 'gsap/all'
import Scrollbar from 'smooth-scrollbar'
import OverscrollPlugin from 'smooth-scrollbar/plugins/overscroll'
import { map } from './utils/utils'
import Scene from './Scene'
import HorizontalScrollPlugin from './utils/HorizontalScrollPlugin'
Scrollbar.use(HorizontalScrollPlugin, OverscrollPlugin)
const offsetTitle = 100
export default class Stage {
constructor() {
this.progress = 0
this.$els = {
title : document.querySelector('.page-title'),
progress : document.querySelector('.slideshow__progress'),
progressCtn : document.querySelector('.slideshow__progress-ctn'),
scene : document.getElementById('scene'),
}
this.init()
this.bindEvents()
}
bindEvents() {
document.addEventListener('lockScroll', ({ detail }) => { this.lockScroll(detail) })
this.Scroll.addListener((s) => { this.onScroll(s) })
}
init() {
this.Scroll = Scrollbar.init(document.querySelector('.scrollarea'), {
delegateTo: document,
continuousScrolling : false,
overscrollEffect: 'bounce',
damping: 0.05,
plugins: {
horizontalScroll: {
events: [/wheel/],
},
},
})
this.Scroll.track.xAxis.element.remove()
this.Scroll.track.yAxis.element.remove()
Scrollbar.detachStyle()
this.updateScrollBar()
this.scene = new Scene(this.$els.scene)
}
/* Handlers
--------------------------------------------------------- */
onScroll({ limit, offset }) {
this.progress = offset.x / limit.x
TM.to(this.$els.title, 0.3, { x: -this.progress * offsetTitle, force3D: true })
this.updateScrollBar()
}
/* Actions
--------------------------------------------------------- */
updateScrollBar() {
const progress = map(this.progress * 100, 0, 100, 5, 100)
TM.to(this.$els.progress, 0.3, { xPercent: progress, force3D: true })
}
lockScroll({ lock }) {
const duration = lock ? 0 : 1.8
TM.delayedCall(duration, () => {
this.Scroll.updatePluginOptions('horizontalScroll', {
events: lock ? [] : [/wheel/],
})
TM.to(this.$els.progressCtn, 0.5, {
alpha: lock ? 0 : 1,
force3D: true,
})
})
}
/* Values
--------------------------------------------------------- */
}