-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.html
More file actions
111 lines (100 loc) · 3.62 KB
/
random.html
File metadata and controls
111 lines (100 loc) · 3.62 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edge Smooth Scrolling</title>
<style>
/* Reset Styles */
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
/* Outer Container */
.outer-container {
height: 100%;
overflow: hidden;
position: relative;
}
/* Inner Wrapper */
.inner-wrapper {
height: 100%;
transition: transform 0.8s ease; /* Smooth transition */
}
/* Individual Sections */
.section {
height: 100vh; /* Full viewport height */
overflow-y: auto; /* Allow normal scrolling within sections */
padding: 20px;
box-sizing: border-box;
}
.section:nth-child(odd) {
background-color: #6a5acd;
color: white;
}
.section:nth-child(even) {
background-color: #ff6347;
color: white;
}
</style>
</head>
<body>
<div class="outer-container">
<div class="inner-wrapper" id="innerWrapper">
<div class="section">
<h1>Section 1</h1>
<p>Scroll down to transition to the next section.</p>
<p style="margin-top: 1200px;">End of Section 1</p>
</div>
<div class="section">
<h1>Section 2</h1>
<p>Scroll freely in this section.</p>
<p style="margin-top: 1200px;">End of Section 2</p>
</div>
<div class="section">
<h1>Section 3</h1>
<p>Scroll down to transition to the next section.</p>
<p style="margin-top: 1200px;">End of Section 3</p>
</div>
</div>
</div>
<script>
const innerWrapper = document.getElementById('innerWrapper');
const sections = document.querySelectorAll('.section');
const threshold = 50; // Adjust this for edge detection
let currentSection = 0;
let isTransitioning = false;
// Scroll event listener for each section
sections.forEach((section, index) => {
section.addEventListener('scroll', () => {
if (isTransitioning) return;
const scrollTop = section.scrollTop;
const scrollHeight = section.scrollHeight;
const clientHeight = section.clientHeight;
if (scrollTop + clientHeight >= scrollHeight - threshold && index < sections.length - 1) {
// Near the bottom edge -> Transition to the next section
isTransitioning = true;
currentSection++;
smoothTransition();
} else if (scrollTop <= threshold && index > 0) {
// Near the top edge -> Transition to the previous section
isTransitioning = true;
currentSection--;
smoothTransition();
}
});
});
// Smoothly transition between sections
function smoothTransition() {
const translateY = -currentSection * 100;
innerWrapper.style.transform = `translateY(${translateY}vh)`;
// Allow a delay for the transition to complete before enabling further transitions
setTimeout(() => {
isTransitioning = false;
}, 800); // Match the transition duration
}
</script>
</body>
</html>