-
-
Notifications
You must be signed in to change notification settings - Fork 7k
/
expand-transition.js
39 lines (30 loc) · 1.02 KB
/
expand-transition.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
import { addOnceEventListener } from '../../util/helpers'
export default function (expandedParentClass = '') {
return {
enter (el, done) {
el._parent = el.parentNode
addOnceEventListener(el, 'transitionend', done)
// Get height that is to be scrolled
el.style.overflow = 'hidden'
el.style.height = 0
el.style.display = 'block'
expandedParentClass && el._parent.classList.add(expandedParentClass)
setTimeout(() => (el.style.height = `${el.scrollHeight}px`), 100)
},
afterEnter (el) {
el.style.overflow = null
el.style.height = null
},
leave (el, done) {
// Remove initial transition
addOnceEventListener(el, 'transitionend', done)
// Set height before we transition to 0
el.style.overflow = 'hidden'
el.style.height = `${el.offsetHeight}px`
setTimeout(() => (el.style.height = 0), 100)
},
afterLeave (el) {
expandedParentClass && el._parent && el._parent.classList.remove(expandedParentClass)
}
}
}