-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
200 lines (196 loc) · 5.99 KB
/
app.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
let controller;
let slideScene;
let pageScene;
let detailScene;
function animateSlides() {
//Init Controller
controller = new ScrollMagic.Controller();
//Select some things
const sliders = document.querySelectorAll('.slide');
const nav = document.querySelector('.nav-header');
//Loop over each sllide
sliders.forEach((slide, index, slides) => {
const revealImg = slide.querySelector('.reveal-img');
const img = slide.querySelector('img');
const revealText = slide.querySelector('.reveal-text');
//GSAP
const slideTl = gsap.timeline({
defaults: { duration: 1, ease: 'power2.inOut' },
});
slideTl.fromTo(revealImg, { x: '0%' }, { x: '100%' });
slideTl.fromTo(img, { scale: 2 }, { scale: 1 }, '-=1');
slideTl.fromTo(revealText, { x: '0%' }, { x: '100%' }, '-=0.75');
//Create Scene
slideScene = new ScrollMagic.Scene({
triggerElement: slide,
triggerHook: 0.25,
reverse: false,
})
.setTween(slideTl)
// .addIndicators({
// colorStart: "white",
// colorTrigger: "white",
// name: "slide"
// })
.addTo(controller);
//New ANimation
const pageTl = gsap.timeline();
let nextSlide = slides.length - 1 === index ? 'end' : slides[index + 1];
pageTl.fromTo(nextSlide, { y: '0%' }, { y: '50%' });
pageTl.fromTo(slide, { opacity: 1, scale: 1 }, { opacity: 0, scale: 0.5 });
pageTl.fromTo(nextSlide, { y: '50%' }, { y: '0%' }, '-=0.5');
//Create new scene
pageScene = new ScrollMagic.Scene({
triggerElement: slide,
duration: '100%',
triggerHook: 0,
})
// .addIndicators({
// colorStart: "white",
// colorTrigger: "white",
// name: "page",
// indent: 200
// })
.setPin(slide, { pushFollowers: false })
.setTween(pageTl)
.addTo(controller);
});
}
const mouse = document.querySelector('.cursor');
const mouseTxt = mouse.querySelector('span');
const burger = document.querySelector('.burger');
function cursor(e) {
mouse.style.top = e.pageY + 'px';
mouse.style.left = e.pageX + 'px';
}
function activeCursor(e) {
const item = e.target;
if (item.id === 'logo' || item.classList.contains('burger')) {
mouse.classList.add('nav-active');
} else {
mouse.classList.remove('nav-active');
}
if (item.classList.contains('explore')) {
mouse.classList.add('explore-active');
gsap.to('.title-swipe', 1, { y: '0%' });
mouseTxt.innerText = 'Tap';
} else {
mouse.classList.remove('explore-active');
mouseTxt.innerText = '';
gsap.to('.title-swipe', 1, { y: '100%' });
}
}
function navToggle(e) {
if (!e.target.classList.contains('active')) {
e.target.classList.add('active');
gsap.to('.line1', 0.5, { rotate: '45', y: 5, background: 'black' });
gsap.to('.line2', 0.5, { rotate: '-45', y: -5, background: 'black' });
gsap.to('#logo', 1, { color: 'black' });
gsap.to('.nav-bar', 1, { clipPath: 'circle(2500px at 100% -10%)' });
document.body.classList.add('hide');
} else {
e.target.classList.remove('active');
gsap.to('.line1', 0.5, { rotate: '0', y: 0, background: 'white' });
gsap.to('.line2', 0.5, { rotate: '0', y: 0, background: 'white' });
gsap.to('#logo', 1, { color: 'white' });
gsap.to('.nav-bar', 1, { clipPath: 'circle(50px at 100% -10%)' });
document.body.classList.remove('hide');
}
}
//Barba Page Transitions
const logo = document.querySelector('#logo');
barba.init({
views: [
{
namespace: 'home',
beforeEnter() {
animateSlides();
logo.href = './index.html';
},
beforeLeave() {
slideScene.destroy();
pageScene.destroy();
controller.destroy();
},
},
{
namespace: 'fashion',
beforeEnter() {
logo.href = '../index.html';
detailAnimation();
},
beforeLeave() {
controller.destroy();
detailScene.destroy();
},
},
],
transitions: [
{
leave({ current, next }) {
let done = this.async();
//An Animation
const tl = gsap.timeline({ defaults: { ease: 'power2.inOut' } });
tl.fromTo(current.container, 1, { opacity: 1 }, { opacity: 0 });
tl.fromTo(
'.swipe',
0.75,
{ x: '-100%' },
{ x: '0%', onComplete: done },
'-=0.5'
);
},
enter({ current, next }) {
let done = this.async();
//Scroll to the top
window.scrollTo(0, 0);
//An Animation
const tl = gsap.timeline({ defaults: { ease: 'power2.inOut' } });
tl.fromTo(
'.swipe',
1,
{ x: '0%' },
{ x: '100%', stagger: 0.2, onComplete: done }
);
tl.fromTo(next.container, 1, { opacity: 0 }, { opacity: 1 });
tl.fromTo(
'.nav-header',
1,
{ y: '-100%' },
{ y: '0%', ease: 'power2.inOut' },
'-=1.5'
);
},
},
],
});
function detailAnimation() {
controller = new ScrollMagic.Controller();
const slides = document.querySelectorAll('.detail-slide');
slides.forEach((slide, index, slides) => {
const slideTl = gsap.timeline({ defaults: { duration: 1 } });
let nextSlide = slides.length - 1 === index ? 'end' : slides[index + 1];
const nextImg = nextSlide.querySelector('img');
slideTl.fromTo(slide, { opacity: 1 }, { opacity: 0 });
slideTl.fromTo(nextSlide, { opacity: 0 }, { opacity: 1 }, '-=1');
slideTl.fromTo(nextImg, { x: '50%' }, { x: '0%' });
//Scene
detailScene = new ScrollMagic.Scene({
triggerElement: slide,
duration: '100%',
triggerHook: 0,
})
.setPin(slide, { pushFollowers: false })
.setTween(slideTl)
// .addIndicators({
// colorStart: "white",
// colorTrigger: "white",
// name: "detailScene"
// })
.addTo(controller);
});
}
//EventListeners
burger.addEventListener('click', navToggle);
window.addEventListener('mousemove', cursor);
window.addEventListener('mouseover', activeCursor);