Refactor code structure for improved readability and maintainability

This commit is contained in:
Tomas Dvorak
2025-05-05 11:47:24 +02:00
parent 2eb906ce1e
commit 440023af7d
2 changed files with 67 additions and 8412 deletions
+67 -12
View File
@@ -1191,19 +1191,72 @@ footer::before {
navMenu.classList.toggle('show'); navMenu.classList.toggle('show');
}); });
// Carousel navigation // Carousel functionality
nextBtn.addEventListener('click', function() { let autoScrollInterval;
carousel.scrollBy({
left: 300, function scrollCarousel(direction) {
behavior: 'smooth' const scrollAmount = 300;
}); const maxScroll = carousel.scrollWidth - carousel.clientWidth;
if (direction === 'next') {
if (carousel.scrollLeft >= maxScroll) {
// If at the end, smoothly scroll back to start
carousel.scrollTo({
left: 0,
behavior: 'smooth'
});
} else {
carousel.scrollBy({
left: scrollAmount,
behavior: 'smooth'
});
}
} else {
if (carousel.scrollLeft <= 0) {
// If at the start, smoothly scroll to end
carousel.scrollTo({
left: maxScroll,
behavior: 'smooth'
});
} else {
carousel.scrollBy({
left: -scrollAmount,
behavior: 'smooth'
});
}
}
}
// Start auto-scrolling
function startAutoScroll() {
autoScrollInterval = setInterval(() => {
scrollCarousel('next');
}, 3000); // Scroll every 3 seconds
}
// Stop auto-scrolling
function stopAutoScroll() {
clearInterval(autoScrollInterval);
}
// Initialize auto-scroll
startAutoScroll();
// Pause auto-scroll on hover
carousel.addEventListener('mouseenter', stopAutoScroll);
carousel.addEventListener('mouseleave', startAutoScroll);
// Button controls
nextBtn.addEventListener('click', () => {
stopAutoScroll();
scrollCarousel('next');
startAutoScroll();
}); });
prevBtn.addEventListener('click', function() { prevBtn.addEventListener('click', () => {
carousel.scrollBy({ stopAutoScroll();
left: -300, scrollCarousel('prev');
behavior: 'smooth' startAutoScroll();
});
}); });
// Feature card interactions // Feature card interactions
@@ -1237,5 +1290,7 @@ footer::before {
}); });
}); });
</script> </script>
</body> </body>
</html> </html>
```
-8400
View File
File diff suppressed because it is too large Load Diff