forked from deivthings/vue-sequential-entrance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SequentialEntrance.js
45 lines (39 loc) · 1.13 KB
/
SequentialEntrance.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
import { defineComponent, h } from 'vue'
const sequentialEntrance = defineComponent({
name: 'sequentialEntrance',
props: {
tag: {
type: String,
default: 'div'
},
delay: {
type: String,
default: '250',
},
animation: {
type: String,
default: 'entranceFromRight'
}
},
render () {
const children = this.$slots.default()
let animation = null
if (this.$props.fromTop !== undefined) animation = 'entranceFromTop'
else if (this.$props.fromLeft !== undefined) animation = 'entranceFromLeft'
else if (this.$props.fromRight !== undefined) animation = 'entranceFromRight'
else if (this.$props.fromBottom !== undefined) animation = 'entranceFromBottom'
else animation = this.$props.animation
if (children && children[0].children.length) {
children[0].children.forEach((child, index) => {
setTimeout(() => {
child.el.style.opacity = '0'
child.el.style.animationFillMode = 'forwards'
child.el.style.animationDelay = index * this.$props.delay + 'ms'
child.el.classList.add(animation)
}, 10)
})
}
return h(this.$props.tag, { }, children)
}
})
export default sequentialEntrance