<script>
const mediaMD = 768;
const windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
if (windowWidth >= mediaMD) {
const sections = document.querySelectorAll('.section');
let current = 0;
const throttle = (callback, delay) => {
let callable = true;
return function (...args) {
if (callable) {
callable = false;
callback.apply(this, args);
setTimeout(() => {
callable = true;
}, delay);
}
};
};
const changeSection = throttle((event) => {
const direction = Math.sign(event.deltaY);
current += direction;
if (current > sections.length - 1) {
current = 0;
}
if (current < 0) {
current = sections.length - 1;
}
sections[current].scrollIntoView({
behavior: 'smooth'
});
}, 850);
window.addEventListener('wheel', (event) => {
event.preventDefault();
changeSection(event);
}, {
passive: false
});
window.addEventListener('scroll', (event) => {
event.preventDefault();
});
}
</script>
проверка ширины не отключает скрипт
if (window.matchMedia("(min-width: 400px)").matches) {
/* the viewport is at least 400 pixels wide */
} else {
/* the viewport is less than 400 pixels wide */
}
и matchMedia тоже не помогает