forked from FrontendMatter/material-design-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblend-background.js
More file actions
32 lines (28 loc) · 881 Bytes
/
Copy pathblend-background.js
File metadata and controls
32 lines (28 loc) · 881 Bytes
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
const FRONT_LAYER = '[class*="__bg-front"]'
const REAR_LAYER = '[class*="__bg-rear"]'
/**
* blend-background effect
*/
export const SCROLL_EFFECT_BLEND_BACKGROUND = {
name: 'blend-background',
setUp () {
let frontLayer = this.element.querySelector(FRONT_LAYER)
let rearLayer = this.element.querySelector(REAR_LAYER)
const layers = [ frontLayer, rearLayer ]
layers.map(layer => {
if (layer) {
if (layer.style.transform === '') {
this._transform('translateZ(0)', layer)
layer.style.willChange = 'opacity'
}
}
})
rearLayer.style.opacity = 0
},
run (progress, top) {
let frontLayer = this.element.querySelector(FRONT_LAYER)
let rearLayer = this.element.querySelector(REAR_LAYER)
frontLayer.style.opacity = (1 - progress).toFixed(5)
rearLayer.style.opacity = progress.toFixed(5)
}
}