-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsap-starter-links.html
230 lines (208 loc) · 6.08 KB
/
gsap-starter-links.html
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gsap3</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/ScrollTrigger.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/ScrollToPlugin.min.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/TextPlugin.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/Observer.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/Flip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/Draggable.min.js"></script> -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800;900&family=Quicksand:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
<script>
document.addEventListener('DOMContentLoaded', function (event) {
window.onload = () => {
gsap.registerPlugin(ScrollTrigger, ScrollToPlugin)
const sections = gsap.utils.toArray('section')
const links = gsap.utils.toArray('.link')
const boxes = gsap.utils.toArray('.box')
const animation = gsap.timeline({
repeat: 1,
yoyo: true,
})
animation
.to('.box', {
// xPercent: 200, // translateX(200%)
x: 600, // translateX(400px)
rotate: 360,
ease: 'none',
})
.to('.box', {
ease: 'none',
})
boxes.forEach((el, index) => {
ScrollTrigger.create({
markers: true, // Show markers
id: 'box', // Marker name
trigger: el,
start: 'top top', // trigger viewport
end: '+=300 top', // trigger viewport
pin: true,
animation: animation,
scrub: true, // trigger animation on scroll
})
})
sections.forEach((el, index) => {
ScrollTrigger.create({
markers: true, // Show markers
id: 'section', // Marker name
trigger: el,
start: 'top center', // trigger viewport
// Cool links
onEnter: () => {
links.forEach((e, i) => {
links[i].classList.remove('active')
})
links[index].classList.add('active')
},
onEnterBack: () => {
links.forEach((e, i) => {
links[i].classList.remove('active')
})
links[index].classList.add('active')
},
// Poor links
// toggleClass: { targets: links[index], className: 'active' },
})
})
// Scroll to link on click
links.forEach((link, index) => {
// Link objects
let trigger = ScrollTrigger.create({
trigger: sections[index],
start: 'top top',
})
// Click events
link.addEventListener('click', (e) => {
e.preventDefault()
if (index > 0) {
gsap.to(window, { scrollTo: trigger.start })
} else {
gsap.to(window, { scrollTo: 0 })
}
})
})
}
})
</script>
<style>
:root {
--bg: #88ce04;
--font-size: 16px;
--font-size-mid: 30px;
--font-size-big: 50px;
}
* {
outline: none;
box-sizing: border-box;
}
body {
margin: 0px;
padding: 0px;
background: var(--bg);
font-size: var(--font-size);
font-family: 'Poppins', sans-serif;
overflow-y: scroll;
}
section {
height: 1200px;
position: relative;
border-bottom: 1px solid #785235;
box-sizing: border-box;
}
.box {
position: relative;
width: 200px;
height: 200px;
color: #fff;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
z-index: 1;
}
.box-copy {
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 200px;
color: #666;
background: #222;
border: 2px solid #666;
display: flex;
align-items: center;
justify-content: center;
z-index: 0;
font-size: 99px;
font-weight: 900;
}
.c1 {
background: #55cc55;
box-shadow: 0px 0px 0px 10px #55cc5533;
}
.c2 {
background: #dd6030;
box-shadow: 0px 0px 0px 10px #dd603033;
}
.c3 {
background: #ff2233;
box-shadow: 0px 0px 0px 10px #ff223333;
}
.kratka {
background: #2a2a2a;
background-image: linear-gradient(rgba(255, 255, 255, 0.07) 2px, transparent 2px), linear-gradient(90deg, rgba(255, 255, 255, 0.07) 2px, transparent 2px), linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
background-position: -2px -2px, -2px -2px, -1px -1px, -1px -1px;
}
.menu-links {
position: fixed;
bottom: 20px;
right: 30px;
}
.menu-links .link {
padding: 10px 15px;
margin-bottom: 5px;
color: #000;
background: #fff;
cursor: pointer;
}
.menu-links .active {
background: #09f;
}
</style>
</head>
<body class="kratka">
<div id="smooth-wrapper">
<div id="smooth-content">
<!--- ALL YOUR CONTENT HERE --->
<section>
<div class="box-copy">1</div>
<div class="box c1">Hello !</div>
</section>
<section>
<div class="box-copy">2</div>
<div class="box c2">Hello !</div>
</section>
<section>
<div class="box-copy">3</div>
<div class="box c3">Hello !</div>
</section>
<section>
<div class="box-copy">😎</div>
</section>
<div class="menu-links">
<div class="link active">1</div>
<div class="link">2</div>
<div class="link">3</div>
<div class="link">4</div>
</div>
</div>
</div>
</body>
</html>