-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
164 lines (152 loc) · 3.06 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
console.clear();
console.log("System Started");
const stage = document.querySelector('svg');
const imgFg = document.querySelector('#imgFg')
const imgBg = document.querySelector('#imgBg')
const imgs = [
'https://images.unsplash.com/photo-1506744038136-46273834b3fb?w=2000&q=50',
'https://images.unsplash.com/photo-1511576661531-b34d7da5d0bb?w=2000&q=50',
'https://images.unsplash.com/photo-1476610182048-b716b8518aae?w=2000&q=50',
'https://images.unsplash.com/photo-1502657877623-f66bf489d236?w=2000&q=50',
'https://images.unsplash.com/photo-1506361797048-46a149213205?w=2000&q=50'
]
const pos = {
x: innerWidth / 2,
y: innerHeight / 2
}
for (let i = 0; i < imgs.length; i++) {
const img = document.createElementNS("http://www.w3.org/2000/svg", "image")
imgBg.appendChild(img)
gsap.set(img, {
attr: {
x: '-5%',
y: '-5%',
width: '110%',
height: '110%',
href: imgs[i],
preserveAspectRatio: 'xMidYMid slice'
}
})
}
window.addEventListener('resize', () => {
pos.x = innerWidth / 2
pos.y = innerHeight / 2
gsap.set('circle', {
duration: 0.3,
attr: {
cx: pos.x,
cy: pos.y
}
})
})
stage.addEventListener('mouseenter', (e) => {
loop.pause()
stage.addEventListener('mousemove', mouseFollow)
mouseClickOn()
})
stage.addEventListener('mouseleave', (e) => {
mouseClickOff()
stage.removeEventListener('mousemove', mouseFollow)
pos.x = innerWidth / 2
pos.y = innerHeight / 2
gsap.to('circle', {
attr: {
cx: pos.x,
cy: pos.y
},
ease: 'power2.inOut'
})
gsap.to(imgFg.children[0], {
attr: {
x: '-5%',
y: '-5%'
}
})
loop.play(0)
})
function mouseClickOn() {
stage.addEventListener('mousedown', maskConstrict)
stage.addEventListener('mouseup', nextImg)
}
function mouseClickOff() {
stage.removeEventListener('mousedown', maskConstrict)
stage.removeEventListener('mouseup', nextImg)
}
function mouseFollow(e) {
pos.x = e.pageX
pos.y = e.pageY
gsap.to('circle', {
duration: 0.3,
attr: {
cx: pos.x,
cy: pos.y
}
})
gsap.to(imgFg.children[0], {
attr: {
x: gsap.utils.interpolate('0%', '-10%', pos.x / innerWidth),
y: gsap.utils.interpolate('0%', '-10%', pos.y / innerHeight)
}
})
}
function maskConstrict(e) {
gsap.to('circle', {
duration: 0.3,
attr: {
r: (i) => [30, 50][i]
}
})
}
function nextImg() {
mouseClickOff()
gsap.timeline()
.to('circle', {
duration: 0.4,
attr: {
r: innerWidth
},
ease: 'power3.in',
stagger: -0.1
})
.add(() => {
imgFg.append(imgBg.children[imgBg.children.length - 1])
imgBg.prepend(imgFg.children[0])
gsap.set('circle', {
attr: {
r: 0
}
})
})
.fromTo('circle', {
attr: {
r: 0,
cx: pos.x,
cy: pos.y
}
}, {
attr: {
r: (i) => [35, 45][i]
},
ease: 'power2.inOut',
stagger: -0.1
}, 0.5)
.add(mouseClickOn)
}
imgFg.append(imgBg.children[imgBg.children.length - 1])
gsap.fromTo('circle', {
attr: {
cx: pos.x,
cy: pos.y
}
}, {
attr: {
r: (i) => [35, 45][i]
},
ease: 'power2.inOut'
})
const loop = gsap.timeline({
repeatRefresh: true,
repeat: -1
})
.add(maskConstrict, 3)
.add(nextImg, 3.15)