только код должен быть в ванильном javascript. < /p>
Код: Выделить всё
let sections = document.querySelectorAll(".section")
let sectionsWrap = document.getElementById("sections-wrap")
let currentSectionIndex = 0
let isScrolling = false
let scrollToSection = (index) => {
sectionsWrap.style.transform = `translateY(-${index * 100}%)`
sectionsWrap.style.transition = "transform 1s ease-in-out"
}
window.addEventListener("wheel", (event) => {
if (isScrolling) return
if (event.deltaY > 0 && currentSectionIndex < sections.length - 1) {
currentSectionIndex++
} else if (event.deltaY < 0 && currentSectionIndex > 0) {
currentSectionIndex--
} else {
return
}
isScrolling = true
scrollToSection(currentSectionIndex)
html,
body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
#sections-wrap {
width: 100%;
height: 100%;
height: 100%;
}
.section {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 2rem;
color: white;
}
.section:nth-child(1) {
background: #ff5733;
}
.section:nth-child(2) {
background: #33ff57;
}
.section:nth-child(3) {
background: #3357ff;
}
.section:nth-child(4) {
background: #ff33a1;
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... s-at-a-tim
Мобильная версия