-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstacked-card.html
212 lines (208 loc) · 5.63 KB
/
stacked-card.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stacked Cards</title>
<!--Google Fonts-->
<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=Plus+Jakarta+Sans:wght@200;300;400;500;600;700;800&family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap"
rel="stylesheet"
/>
<style>
body {
width: 100%;
height: fit-content;
margin: 0;
padding: 0;
}
.center {
width: 100%;
height: fit-content;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.stack-area {
width: 100%;
height: 300vh;
position: relative;
display: flex;
justify-content: center;
}
.right,
.left {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
position: sticky;
top: 0;
box-sizing: border-box;
flex-basis: 50%;
}
.cards {
width: 100%;
height: 100%;
position: relative;
}
.card {
width: 350px;
height: 350px;
box-sizing: border-box;
padding: 35px;
border-radius: 6mm;
display: flex;
justify-content: space-between;
flex-direction: column;
position: absolute;
top: 50%;
left: 50%;
transition: 0.5s ease-in-out;
}
.card:nth-child(1) {
background: rgb(64, 122, 255);
z-index: 4;
}
.card:nth-child(2) {
background: rgb(221, 62, 88);
z-index: 3;
}
.card:nth-child(3) {
background: rgb(186, 113, 245);
z-index: 2;
}
.card:nth-child(4) {
background: rgb(247, 92, 208);
z-index: 1;
}
.sub {
font-family: poppins;
font-size: 20px;
font-weight: 700;
}
.content {
font-family: poppins;
font-size: 44px;
font-weight: 700;
line-height: 54px;
}
.card.active {
transform-origin: bottom left;
}
.left {
align-items: center;
flex-direction: column;
}
.title {
width: 420px;
font-size: 84px;
font-family: poppins;
font-weight: 700;
line-height: 88px;
}
.sub-title {
width: 420px;
font-family: poppins;
font-size: 14px;
margin-top: 30px;
}
.sub-title button {
font-family: poppins;
font-size: 14px;
padding: 15px 30px;
background: black;
color: white;
border-radius: 8mm;
border: none;
outline: none;
cursor: pointer;
margin-top: 20px;
}
.top,
.bottom {
width: 100%;
height: 100vh;
font-family: poppins;
font-size: 70px;
display: flex;
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<div class="center">
<div class="top">Scroll Down</div>
<div class="stack-area">
<div class="left">
<div class="title">Our Features</div>
<div class="sub-title">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Sapiente
qui quis, facere, cupiditate, doloremque natus ex perspiciatis
ratione hic corrupti adipisci ea doloribus!
<br />
<button>See More Details</button>
</div>
</div>
<div class="right">
<div class="cards">
<div class="card">
<div class="sub">Simplified</div>
<div class="content">Complex tasks are now simple</div>
</div>
<div class="card">
<div class="sub">Boost Productivity</div>
<div class="content">Perform Tasks in less time</div>
</div>
<div class="card">
<div class="sub">Facilitated learning</div>
<div class="content">train anyone from anywhere</div>
</div>
<div class="card">
<div class="sub">Support</div>
<div class="content">Now its 24/7 support</div>
</div>
</div>
</div>
</div>
<div class="bottom">Other Content...</div>
</div>
<script>
let cards = document.querySelectorAll(".card")
let stackArea = document.querySelector(".stack-area")
function rotateCards() {
let angle = 0
cards.forEach((card) => {
if (card.classList.contains("active")) {
card.style.transform = `translate(-50%, -120vh) rotate(-48deg)`
} else {
card.style.transform = `translate(-50%, -50%) rotate(${angle}deg)`
angle = angle - 10
}
})
}
rotateCards()
window.addEventListener("scroll", () => {
let proportion =
stackArea.getBoundingClientRect().top / window.innerHeight
if (proportion <= 0) {
let n = cards.length
let index = Math.ceil((proportion * n) / 2)
index = Math.abs(index) - 1
for (let i = 0; i < n; i++) {
if (i <= index) {
cards[i].classList.add("active")
} else {
cards[i].classList.remove("active")
}
}
rotateCards()
}
})
</script>
</body>
</html>