使用CSS实现滚动吸附效果
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
*{
margin: 0;padding: 0;
}
.container{
width: 100%;
height: 400px;
display: flex;
overflow-x:scroll;
scroll-snap-type: x mandatory;
}
.container::-webkit-scrollbar{
width: 0;
}
.item{
width: 100%;
height: 100%;
flex-shrink: 0;
display: flex;
justify-content: center;
align-items: center;
font-size: 16px;
scroll-snap-align: start;
scroll-snap-stop: always;
}
.item:nth-child(1){
background-color: aqua;
}
.item:nth-child(2){
background-color: rebeccapurple;
}
.item:nth-child(3){
background-color:green;
}
</style>
</head>
<body>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
</body>
</html>