整页翻动效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>整页翻动效果</title>
<style>
*{
margin: 0;
padding: 0;
list-style: none;
}
body{
height: 100vh;
overflow: hidden;
}
.container{
transform: translateY(0vh);
transition: 0.5s;
}
.container div{
height: 100vh;
}
.indexs{
width: 20px;
position: fixed;
right: 10px;
top: 50%;
transform: translate(-50%);
}
.indexs li{
width: 12px;
height: 12px;
border-radius: 50%;
background-color: #000;
margin: 10px 0;
}
.indexs li.active{
background-color: #fff;
}
</style>
</head>
<body>
<div class="container">
<div style="background-color: skyblue;"></div>
<div style="background-color: slateblue;"></div>
<div style="background-color: slategray;"></div>
<div style="background-color: yellowgreen;"></div>
<div style="background-color: wheat;"></div>
</div>
<ul class="indexs">
<li class="active"></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<script>
let i = 0;
let container = document.querySelector('.container')
let indexs = document.querySelector('.indexs')
let endTime = new Date();
window.onmousewheel = e => {
if(new Date() - endTime < 500) return;
if(e.wheelDeltaY < 0){
if(i===4) return;
i++
}else{
if(i===0) return;
i--
}
container.style.transform = `translateY(-${i * 100}vh)`
let active = document.querySelector('.indexs li.active')
active.classList.remove('active')
indexs.children[i].classList.add('active')
endTime = new Date();
}
for(let j = 0;j<indexs.children.length;j++){
indexs.children[j].onmouseenter = function(){
let active = document.querySelector('.indexs li.active')
active.classList.remove('active')
this.classList.add('active')
i = j
container.style.transform = `translateY(-${i * 100}vh)`
}
}
</script>
</body>
</html>