css - 像 Firefox 一样的 CSS Scroll Snap 行为
问题描述
我在除 macOS 和 android 上的 firefox 之外的所有浏览器上都遇到了问题(尚未测试过 windows 和 ios),其中滚动捕捉被延迟。在 Firefox 上运行良好,但在 Edge、Chrome 和 Safari 上运行延迟。有什么解决办法吗?
我的代码:
.scroll-snap-container {
height: 100vh;
scroll-snap-type: mandatory;
scroll-snap-points-y: repeat(100vh);
scroll-snap-type: y mandatory;
scroll-behavior: smooth;
overflow-scrolling: touch; /* Needed to work on iOS Safari */
overflow: auto;
}
.scroll-snap-container > div {
height: 100vh;
scroll-snap-align: start;
scroll-snap-stop: always;
position: relative;
}
p {
background-color: #000a;
color: white;
position: absolute;
}
img {
height: 100vh;
scroll-snap-align: start;
scroll-snap-stop: always;
}
<div class="scroll-snap-container">
<div>
<p>Long text here.</p>
<img src="https://placeimg.com/640/480/any/sepia"/>
</div>
<div>
<p>Long text here.</p>
<img src="https://placeimg.com/641/480/any/sepia"/>
</div>
<div>
<p>Long text here.</p>
<img src="https://placeimg.com/642/480/any/sepia"/>
</div>
</div>
编辑:添加了 html 片段
解决方案
推荐阅读
- flutter - Flutter 2:带有TextPainter的渐变文本在列中中断
- mysql - 节点红色和主机数据库连接
- mongodb - 如何在 MongoDB 中获取限制数据?
- c++ - 了解指向类型类成员的指针 - 无多态性
- angular - 如何使带有 Zone.JS 的 Angular Universal 等待 AWS Lambda SDK 调用调用
- react-native - KeyboardAwareScrollView 导致抖动
- selenium - C#中的窗口管理
- google-chrome-extension - 从网页向 chrome 扩展发送消息。Chrome.runtime.lastError
- css - 如何向现有的引导导航栏添加自定义颜色
- reactjs - React 测试库 - 测试后代元素