document.addEventListener('scroll', function () {
// Получаем все блоки
const nextBlocks = document.querySelectorAll('.uc-next1, .uc-next2, .uc-next3, .uc-next4, .uc-next5');
const fixBlocks = document.querySelectorAll('.uc-fix1, .uc-fix2, .uc-fix3, .uc-fix4, .uc-fix5');
// Функция для проверки и фиксации блоков
nextBlocks.forEach((nextBlock, index) => {
const fixBlock = fixBlocks[index];
const nextBlockRect = nextBlock.getBoundingClientRect();
const fixBlockRect = fixBlock.getBoundingClientRect();
// Когда блок .uc-next достигает верхней части экрана
if (nextBlockRect.top <= 0) {
nextBlock.classList.add('fixed');
fixBlock.classList.add('fixed');
// Для блоков .uc-next фиксируем их и двигаем .uc-fix
if (index > 0 && nextBlockRect.top <= 0) {
const prevFixBlock = fixBlocks[index - 1];
prevFixBlock.classList.add('fixed');
}
} else {
nextBlock.classList.remove('fixed');
fixBlock.classList.remove('fixed');
}
});
});