forked from jlmakes/scrollreveal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialize.js
More file actions
43 lines (36 loc) · 1.14 KB
/
initialize.js
File metadata and controls
43 lines (36 loc) · 1.14 KB
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
import each from '../../utils/each'
import { applyStyle } from '../functions/style'
import rinse from './rinse'
export default function initialize() {
rinse.call(this)
each(this.store.elements, element => {
let styles = [element.styles.inline.generated]
if (element.visible) {
styles.push(element.styles.opacity.computed)
styles.push(element.styles.transform.generated.final)
element.revealed = true
} else {
styles.push(element.styles.opacity.generated)
styles.push(element.styles.transform.generated.initial)
element.revealed = false
}
applyStyle(element.node, styles.filter((s) => s !== '').join(' '))
})
each(this.store.containers, container => {
const target =
container.node === document.documentElement ? window : container.node
target.addEventListener('scroll', this.delegate)
target.addEventListener('resize', this.delegate)
})
/**
* Manually invoke delegate once to capture
* element and container dimensions, container
* scroll position, and trigger any valid reveals
*/
this.delegate()
/**
* Wipe any existing `setTimeout` now
* that initialization has completed.
*/
this.initTimeout = null
}