Files
KM_Design/V1/resources/js/index.js
2024-07-20 11:46:10 +02:00

59 lines
1.9 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const carrousel = document.getElementById('carrousel');
if (carrousel) {
new Flickity(carrousel, {
autoPlay: true,
groupCells: '75%',
});
}
const punch = document.getElementById('punch');
const navbar = document.getElementById('navbar');
const homeTitle = document.getElementById('home-title');
const mobileMenuIcon = document.getElementById('mobile-menu-icon');
const mobileMenuItems = document.getElementById('mobile-menu-items');
if (navbar || punch || homeTitle) {
let lastScrollY = window.scrollY;
window.addEventListener('scroll', () => {
let currentScrollY = window.scrollY;
if (navbar) {
if (lastScrollY > currentScrollY) {
navbar.style.top = '0';
} else {
navbar.style.top = '-140px';
}
lastScrollY = currentScrollY;
}
if (punch) {
const punchPosition = punch.getBoundingClientRect();
if (currentScrollY > punchPosition.bottom + (window.innerHeight / 2)) {
punch.style.color = '#F8FAFC';
punch.style.backgroundColor = '#222';
} else {
punch.style.color = '#222';
punch.style.backgroundColor = '#F8FAFC';
}
}
if (homeTitle) {
if (currentScrollY > 1000) {
homeTitle.style.display = 'none';
} else {
homeTitle.style.display = 'flex';
}
}
});
}
if (mobileMenuIcon && mobileMenuItems) {
mobileMenuIcon.addEventListener('click', () => {
mobileMenuItems.style.display = mobileMenuItems.style.display === 'flex' ? 'none' : 'flex';
});
}
});