-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
128 lines (108 loc) · 3.98 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scrolling Race</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
overflow: hidden;
}
.non-scrollable {
padding: 5px;
}
.scrollable-container {
height: 75vh;
overflow-y: hidden;
-webkit-overflow-scrolling: touch;
}
.scrollable {
height: 75vh;
background: linear-gradient(180deg,
rgba(255,0,0,1) 0%, rgba(255,154,0,1) 16.6%, rgba(208,222,33,1) 33.3%,
rgba(79,220,74,1) 50%, rgba(63,218,216,1) 66.6%, rgba(47,201,226,1) 83.3%,
rgba(255,0,0,1) 100%);
background-size: 100% 100%;
}
#rollingNumber {
margin-top: 10px;
font-size: 16px;
}
#controls {
margin-top: 20px;
font-size: 16px;
}
#result {
margin-top: 20px;
font-size: 16px;
}
#result .bold {
font-weight: bold;
}
</style>
</head>
<body>
<div class="scrollable-container" id="scrollableContainer">
<div class="scrollable"></div>
<div class="scrollable"></div>
<div class="scrollable"></div>
</div>
<div class="non-scrollable">
<div id="rollingNumber">0 <span class="bold">px</span></div>
<div id="controls">
<label for="timeLimit">Enter time limit (seconds): </label>
<input type="number" id="timeLimit" min="1" value="5">
<button id="startButton">Start Scrolling Race</button>
</div>
<div id="result"></div>
</div>
<script>
const container = document.getElementById('scrollableContainer');
const rollingNumber = document.getElementById('rollingNumber');
const result = document.getElementById('result');
const startButton = document.getElementById('startButton');
const timeLimitInput = document.getElementById('timeLimit');
let totalScrolledDistance = 0;
let isRaceStarted = false;
let previousScrollTop = 0;
startButton.addEventListener('click', () => {
const timeLimit = parseInt(timeLimitInput.value, 10) || 5;
let countdown = 3;
const countdownInterval = setInterval(() => {
result.textContent = `Race starts in ${countdown}...`;
countdown--;
if (countdown < 0) {
clearInterval(countdownInterval);
result.textContent = 'Go!';
container.style.overflowY = 'scroll';
isRaceStarted = true;
totalScrolledDistance = 0;
previousScrollTop = 0;
setTimeout(() => {
container.style.overflowY = 'hidden';
isRaceStarted = false;
result.innerHTML = `Scrolled Distance: <span class="bold">${totalScrolledDistance} px</span>`;
}, timeLimit * 1000);
}
}, 1000);
});
container.addEventListener('scroll', () => {
if (isRaceStarted) {
const currentScroll = container.scrollTop;
const maxScroll = container.scrollHeight - container.clientHeight;
if (currentScroll > previousScrollTop) {
totalScrolledDistance += currentScroll - previousScrollTop;
}
previousScrollTop = currentScroll;
rollingNumber.innerHTML = `${totalScrolledDistance} <span class="bold">px</span>`;
if (currentScroll >= maxScroll) {
container.scrollTop = 0;
previousScrollTop = 0;
}
}
});
</script>
</body>
</html>