forked from ZjuulOWOW/motion-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransition5.js
70 lines (67 loc) · 2.18 KB
/
transition5.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import barba from '@barba/core'
const imgs = document.querySelectorAll('.projects-link')
imgs.forEach((img) => {
img.addEventListener('click', () => {
img.classList.add('in-transition')
transition(img)
})
})
function transition(img) {
barba.init({
debug: true,
from: {
namespace: [
'about'
]
},
transitions: [{
leave({ current }) {
return new Promise(resolve => {
const content = current.container.querySelectorAll('.projects-link:not(.in-transition), .title')
var imgAnimating = false
content.forEach((el) => {
el.animate({
opacity: 0
},
{
duration: 600,
fill: 'forwards'
}).onfinish = () => {
if (!imgAnimating) {
imgAnimating = true
animateImg()
}
}
})
function animateImg() {
img.animate(
{
width: '100%',
},
{
duration: 600,
fill: 'forwards',
easing: 'cubic-bezier(0,1,1,1)'
}).onfinish = () => resolve()
}
})
},
afterLeave() {
},
enter({next}) {
return new Promise(resolve => {
next.container.animate({
opacity: [0, 1]
},
{
duration: 600,
fill: 'forwards',
}).onfinish = () => resolve()
})
},
afterEnter() {
init()
}
}]
})
}