-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
142 lines (123 loc) · 2.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
//Pin the first page
const tlIntro = gsap.timeline({
scrollTrigger: {
trigger: ".first-page",
start: "0%",
end: "100%",
pin: true,
pinSpacing: false,
},
});
// page 2
const tlH = gsap.timeline({
scrollTrigger: {
trigger: ".second-page",
markers: { startColor: "blue", endColor: "blue" },
scrub: true,
start: "-40%",
end: "40%",
},
});
tlH.fromTo(
".highlight",
{ color: "rgba(255,255,255, 0.4" },
{ color: "rgba(255,255,255, 1", stagger: 1 }
);
const tlHRemove = gsap.timeline({
scrollTrigger: {
trigger: ".second-page",
markers: { startColor: "pink", endColor: "pink" },
scrub: true,
start: "-20%",
end: "60%",
},
});
tlHRemove.to(".highlight", { color: "rgba(255,255,255, 0.4", stagger: 1 });
//Page 3
const tlSplit = gsap.timeline({
scrollTrigger: {
trigger: ".third-page",
start: "-25%",
end: "30%",
markers: true,
scrub: true,
},
});
tlSplit.fromTo(".large-phone", { x: "40%" }, { x: "20%" });
tlSplit.fromTo(".small-phone", { x: "-40%" }, { x: "-20%" }, "<");
tlSplit.fromTo(
".product-text-left",
{ x: 50, opacity: 0 },
{ opacity: 1, x: -50 },
"<"
);
tlSplit.fromTo(
".product-text-right",
{ x: -50, opacity: 0 },
{ opacity: 1, x: 50 },
"<"
);
const tlSplitPin = gsap.timeline({
scrollTrigger: {
trigger: ".third-page",
pin: true,
pinSpacing: false,
start: "0%",
end: "100%",
},
});
// Carousel - page 4
const swatches = document.querySelectorAll(".swatches img");
const gallery = document.querySelector(".phone-gallery");
const slides = document.querySelectorAll(".phone-gallery-container");
let currentSwatch = "blue";
let topIndex = 2;
swatches.forEach((swatch, index) => {
const coord = slides[index].getBoundingClientRect().left;
swatch.addEventListener("click", (e) => {
let swatchName = e.target.getAttribute("swatch");
let closeUp = document.querySelector("." + swatchName);
//Check if we are on the same swatch
if (currentSwatch === swatchName) return;
gsap.set(closeUp, { zIndex: topIndex });
gsap.fromTo(closeUp, { opacity: 0 }, { opacity: 1, duration: 1 });
//Gallery
gsap.to(gallery, { x: -coord, duration: 1, ease: "back.out(1)" });
//Increment zIndex
topIndex++;
currentSwatch = swatchName;
});
});
// Page 5
const tlVideo = gsap.timeline({
scrollTrigger: {
trigger: ".fifth-page",
start: "0%",
end: "100%",
scrub: true,
pin: true,
},
});
tlVideo.fromTo(
".product-video",
{ currentTime: 0 },
{ currentTime: 3, duration: 1 }
);
tlVideo.fromTo(
".product-info-container h4",
{ opacity: 0 },
{ opacity: 1, stagger: 0.25, duration: 0.5 },
"<"
);
// Page 6
const tlParallax = gsap.timeline({
scrollTrigger: {
trigger: ".sixth-page",
start: "-25%",
end: "50%",
scrub: true,
},
});
tlParallax.fromTo(".photo-description", { y: 0 }, { y: -80 });
tlParallax.fromTo(".portrait-container", { y: 0 }, { y: -80 }, "<");
tlParallax.fromTo(".phone-video", { y: 0 }, { y: -100 }, "<");