-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
86 lines (80 loc) · 2.79 KB
/
test.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
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Efekt nakładających się kart</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
scroll-behavior: smooth;
}
body {
overflow-x: hidden;
}
.card-container {
height: 400vh; /* 4 karty * 100vh */
}
.card {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-size: 3em;
color: white;
transition: transform 0.3s ease-out;
}
#card1 { background-color: #ff6b6b; z-index: 4; }
#card2 { background-color: #4ecdc4; z-index: 3; }
#card3 { background-color: #45b7d1; z-index: 2; }
#card4 { background-color: #f7b731; z-index: 1; }
</style>
</head>
<body>
<div class="card-container">
<div class="card" id="card1">Karta 1</div>
<div class="card" id="card2">Karta 2</div>
<div class="card" id="card3">Karta 3</div>
<div class="card" id="card4">Karta 4</div>
</div>
<script>
const cards = document.querySelectorAll('.card');
const cardCount = cards.length;
function updateCards() {
const scrollPosition = window.pageYOffset;
const windowHeight = window.innerHeight;
const totalHeight = windowHeight * (cardCount - 1);
const scrollProgress = Math.min(Math.max(scrollPosition / totalHeight, 0), 1);
cards.forEach((card, index) => {
const cardProgress = (scrollProgress * (cardCount - 1)) - index;
const translateY = Math.min(Math.max(cardProgress * 250, 0), 100);
card.style.transform = `translateY(${translateY}%)`;
});
}
function throttle(func, limit) {
let inThrottle;
return function() {
const args = arguments;
const context = this;
if (!inThrottle) {
func.apply(context, args);
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
}
}
}
const throttledUpdateCards = throttle(updateCards, 10);
window.addEventListener('scroll', throttledUpdateCards);
window.addEventListener('resize', throttledUpdateCards);
updateCards(); // Initial call to set positions
</script>
</body>
</html>