-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsap-starter.html
169 lines (153 loc) · 4.81 KB
/
gsap-starter.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
<!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 boxes = gsap.utils.toArray('.box')
const animation = gsap.timeline()
// Rotate to 360 and back to 0
animation.to('.box', {
rotate: 360,
x: 400,
ease: 'none',
repeat: 1,
yoyo: true,
})
gsap.utils.toArray('.box').forEach((el, i) => {
ScrollTrigger.create({
trigger: el,
start: 'top 300', // trigger viewport
end: 'bottom top', // trigger viewport
pin: true,
animation: animation,
scrub: true, // trigger animation on scroll
markers: true,
// invalidateOnRefresh: true,
// markers: { startColor: '#5c5', endColor: '#f23', fontSize: '16px', fontWeight: 'thin', indent: 20 },
})
})
// Scroll to link on click
boxes.forEach((link, index) => {
let trigger = ScrollTrigger.create({
trigger: boxes[index],
start: 'top top',
})
link.addEventListener('click', (e) => {
e.preventDefault()
if (index > 0) {
gsap.to(window, { scrollTo: trigger.start })
} else {
gsap.to(window, { scrollTo: trigger.start })
// 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: 900px;
position: relative;
}
.box {
position: relative;
width: 200px;
height: 200px;
margin-top: 300px;
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;
}
.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;
}
</style>
</head>
<body class="kratka">
<div id="smooth-wrapper">
<div id="smooth-content">
<!--- ALL YOUR CONTENT HERE --->
<section>
<div class="box c1">Hello Link</div>
<div class="box-copy">Hello Link</div>
</section>
<section>
<div class="box c2">Hello Link</div>
<div class="box-copy">Hello Link</div>
</section>
<section>
<div class="box c3">Hello Link</div>
<div class="box-copy">Hello Link</div>
</section>
<section></section>
</div>
</div>
</body>
</html>