【发布时间】:2022-04-05 11:49:41
【问题描述】:
我正在为 CSS 中的滚动捕捉而苦苦挣扎。
有没有办法只在一个垂直方向上使用滚动捕捉?
我想让它在向下滚动时捕捉到每个部分,但在再次向上滚动时不捕捉。 是否可以在 CSS 中使用,还是我需要一些 JavaScript?
html {
scroll-snap-type: y mandatory;
}
body {
margin: 0;
scroll-snap-type: y mandatory;
}
section {
font-family: sans-serif;
font-size: 12ch;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
scroll-snap-align: start;
}
<head>
<!-- MAIN STYLE -->
<link rel="stylesheet" href="style.css">
</head>
<main>
<section>
<h1>Hello!</h1>
</section>
<section>
<h1>Toodles~</h1>
</section>
<section>
<h1>Boodles~</h1>
</section>
</main>
</html>
【问题讨论】:
-
回答主要问题:你需要 JS。
标签: javascript html css scroll-snap