Skip to content

Commit 95a2956

Browse files
add scroll top-bottom and vice-versa button
1 parent 4acd564 commit 95a2956

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

docs/css/style.css

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,4 +1157,51 @@ html {
11571157

11581158
section {
11591159
scroll-margin-top: 80px;
1160+
}
1161+
1162+
/* Scroll to Top/Bottom Buttons */
1163+
.scroll-btn {
1164+
position: fixed;
1165+
right: var(--space-5); /* 1.25rem */
1166+
width: 50px;
1167+
height: 50px;
1168+
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
1169+
color: var(--white);
1170+
border: none;
1171+
border-radius: 50%;
1172+
display: flex;
1173+
align-items: center;
1174+
justify-content: center;
1175+
cursor: pointer;
1176+
box-shadow: var(--shadow-lg);
1177+
z-index: 100;
1178+
opacity: 0;
1179+
visibility: hidden;
1180+
transform: translateY(20px);
1181+
transition: all var(--transition-normal);
1182+
}
1183+
1184+
.scroll-btn:hover {
1185+
transform: scale(1.1);
1186+
box-shadow: var(--shadow-xl);
1187+
}
1188+
1189+
.scroll-btn.visible {
1190+
opacity: 1;
1191+
visibility: visible;
1192+
transform: translateY(0);
1193+
}
1194+
1195+
#scrollTopBtn {
1196+
bottom: var(--space-5);
1197+
}
1198+
1199+
#scrollBottomBtn {
1200+
/* Position 60px above the top button (50px height + 10px gap) */
1201+
bottom: calc(var(--space-5) + 60px);
1202+
}
1203+
1204+
.scroll-btn svg {
1205+
width: 28px;
1206+
height: 28px;
11601207
}

docs/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,17 @@ <h2 class="download-title">Ready to Boost Your Productivity?</h2>
351351
</div>
352352
</section>
353353

354+
<button id="scrollTopBtn" class="scroll-btn" aria-label="Scroll to top" title="Scroll to top">
355+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
356+
<path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6 1.41 1.41z"/>
357+
</svg>
358+
</button>
359+
<button id="scrollBottomBtn" class="scroll-btn" aria-label="Scroll to bottom" title="Scroll to bottom">
360+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
361+
<path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z"/>
362+
</svg>
363+
</button>
364+
354365
<!-- Footer -->
355366
<footer class="footer">
356367
<div class="container">

docs/js/main.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,58 @@ document.addEventListener('DOMContentLoaded', function() {
313313

314314
// Initialize carousel
315315
carousel.init();
316+
317+
// Get the button elements from the HTML
318+
const scrollTopBtn = document.getElementById('scrollTopBtn');
319+
const scrollBottomBtn = document.getElementById('scrollBottomBtn');
320+
321+
// Function to handle the visibility of both scroll buttons
322+
const handleScrollButtons = () => {
323+
const scrollHeight = document.documentElement.scrollHeight;
324+
const clientHeight = document.documentElement.clientHeight;
325+
const scrollPosition = window.scrollY;
326+
327+
// --- Scroll to Top Button Logic ---
328+
// Show the button if user has scrolled down more than 300px
329+
if (scrollPosition > 300) {
330+
scrollTopBtn.classList.add('visible');
331+
} else {
332+
scrollTopBtn.classList.remove('visible');
333+
}
334+
335+
// --- Scroll to Bottom Button Logic ---
336+
// Show the button if user is near the top, but hide it when they get close to the bottom
337+
const isNearBottom = scrollPosition + clientHeight >= scrollHeight - 300;
338+
if (scrollPosition > 100 && !isNearBottom) {
339+
scrollBottomBtn.classList.add('visible');
340+
} else {
341+
scrollBottomBtn.classList.remove('visible');
342+
}
343+
};
344+
345+
// --- Click Event Listeners ---
346+
347+
// Smoothly scroll to the top of the page
348+
scrollTopBtn.addEventListener('click', () => {
349+
window.scrollTo({
350+
top: 0,
351+
behavior: 'smooth'
352+
});
353+
});
354+
355+
// Smoothly scroll to the bottom of the page
356+
scrollBottomBtn.addEventListener('click', () => {
357+
window.scrollTo({
358+
top: document.body.scrollHeight,
359+
behavior: 'smooth'
360+
});
361+
});
362+
363+
// Add a scroll event listener to the window to check button visibility
364+
window.addEventListener('scroll', handleScrollButtons);
365+
366+
// Initial check when the page loads
367+
handleScrollButtons();
316368
});
317369

318370
// Add some CSS classes for enhanced animations

0 commit comments

Comments
 (0)