【发布时间】:2021-09-11 22:24:35
【问题描述】:
我正在尝试使用 scroll-snap-type: y 强制实现水平滚动;滚动捕捉行为。我能够实现滚动捕捉行为,但不能实现水平滚动。 但是如果我按住 shift 并滚动它可以工作,如果我按箭头键它也可以工作。只是在鼠标滚动上不起作用
可能是什么问题?只能使用CSS解决还是需要JS?
CodePen 链接 - https://codepen.io/manoranjanpanig/pen/dyWvzdK
HTML
<body>
<div class="main-wrapper">
<section class="one">
<h1>First Page</h1>
</section>
<section class="two">
<h1>Second Page</h1>
</section>
<section class="three">
<h1>Third Page</h1>
</section>
</div>
</body>
CSS
*{
margin: 0;
padding: 0;
box-sizing: border-box;
overflow: hidden;
}
body{
width: 100vw;
height: 100vh;
}
.main-wrapper{
display: flex;
width: 100vw;
height: 100vh;
scroll-snap-type: x mandatory ;
overflow-x: scroll;
}
section{
flex: none;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-size: 5rem;
scroll-snap-align: start;
}
.one{
background-color: aqua;
}
.two{
background-color: salmon;
}
.three{
background-color: aquamarine;
}
【问题讨论】: