html - 使用滚动捕捉时的延迟
问题描述
我正在尝试使用滚动捕捉在每个部分之间滚动并使该部分适合视图。但是,当我滚动和该部分捕捉时会有某种延迟。这很奇怪,因为如果我将完全相同的代码放入 codepen(或下面的代码片段),则不会发生延迟。当我使用 codepen 时尝试更具体,我的滚轮的每一步都会滚动到一个新部分。但是,当我不使用 codepen 并且只运行我的 html 文件时,滚动捕捉仅在我停止滚动或向下或向上滚动一步时才会发生,但仅在感觉像 750 毫秒延迟之后才会发生。任何帮助将非常感激。
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Helvetica', sans-serif;
}
/* All the snapping stuff */
.scroll-container {
height: 100vh;
overflow-y: scroll;
overscroll-behavior: contain;
scroll-snap-type: y mandatory;
}
section {
height: 100vh;
scroll-snap-align: center;
}
/* Other styles */
section {
padding: 1rem;
display: flex;
align-items: center;
justify-content: center;
background-color: darkorchid;
}
section:nth-child(2n) {
background-color: turquoise;
}
section:nth-child(3n) {
background-color: tomato;
}
<div class="scroll-container">
<section>
<h2>Section 1</h2>
</section>
<section>
<h2>Section 2</h2>
</section>
<section>
<h2>Section 3</h2>
</section>
<section>
<h2>Section 4</h2>
</section>
</div>
解决方案
推荐阅读
- javascript - 如何连接后端开发服务器和前端开发服务器
- xpath - 从 Ranorex Selocity Chrome 扩展粘贴复制的 Xpath 不起作用
- python - 在张量收缩中利用对称性
- reactjs - Next.js 构建错误:导出在以下路径上遇到错误
- broken-pipe - 如何修复“google.api_core.exceptions.ServiceUnavailable:503 Broken pipe”错误
- sass - 如何通过使用 sass 悬停其他元素来更改其他 div 的样式
- android - Klaxon 没有读取 JSON 中的 JSONObject
- cromwell - 如何告诉 cromwell 和 womtool 使用哪个 WDL 版本?
- r - 在 Shiny 应用程序中复制 mapedit::selectFeatures(..., mode = "click") 的行为
- laravel - 如何在 laravel 中从数据库 groupBy week 获取结果