mirror of
https://github.com/Dvorinka/masterdrinks.git
synced 2026-06-04 02:32:58 +00:00
Refactor code structure for improved readability and maintainability
This commit is contained in:
+66
-11
@@ -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>
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user