main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
941 bytes
|
Line | |
---|
1 | import { CoordinatesEngine } from './CoordinatesEngine'
|
---|
2 | import { scrollValues } from '../utils/events'
|
---|
3 | import { V } from '../utils/maths'
|
---|
4 |
|
---|
5 | export class ScrollEngine extends CoordinatesEngine<'scroll'> {
|
---|
6 | ingKey = 'scrolling' as const
|
---|
7 |
|
---|
8 | scroll(event: UIEvent) {
|
---|
9 | if (!this.state._active) this.start(event)
|
---|
10 | this.scrollChange(event)
|
---|
11 | this.timeoutStore.add('scrollEnd', this.scrollEnd.bind(this))
|
---|
12 | }
|
---|
13 |
|
---|
14 | scrollChange(event: UIEvent) {
|
---|
15 | if (event.cancelable) event.preventDefault()
|
---|
16 | const state = this.state
|
---|
17 | const values = scrollValues(event)
|
---|
18 | state._delta = V.sub(values, state._values)
|
---|
19 | V.addTo(state._movement, state._delta)
|
---|
20 |
|
---|
21 | this.computeValues(values)
|
---|
22 | this.compute(event)
|
---|
23 |
|
---|
24 | this.emit()
|
---|
25 | }
|
---|
26 |
|
---|
27 | scrollEnd() {
|
---|
28 | if (!this.state._active) return
|
---|
29 | this.state._active = false
|
---|
30 | this.compute()
|
---|
31 | this.emit()
|
---|
32 | }
|
---|
33 |
|
---|
34 | bind(bindFunction: any) {
|
---|
35 | bindFunction('scroll', '', this.scroll.bind(this))
|
---|
36 | }
|
---|
37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.