html - css scroll-snap 属性跳过后续页面
问题描述
我目前正在开发一个共有三页的网站。我的想法是添加一个水平滚动捕捉效果。我的问题是它没有捕捉到下一页,而是页面被跳过并捕捉到最后一页。我使用强制捕捉点。
这是我的代码。
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./css/style.css" type="text/css">
<title></title>
</head>
<body>
<div class="container">
<section>
<h1>Page One</h1>
</section>
<section>
<h1>Page Two</h1>
</section>
<section>
<h1>Page Three</h1>
</section>
</div>
</body>
</html>
SCSS
body {
width: 100vw;
height: 100vh;
margin: 0;
.container {
width: 100%;
height: 100%;
scroll-snap-type: x mandatory;
overflow: hidden;
overflow-x: scroll;
display: flex;
section {
flex: none;
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
scroll-snap-align: start;
&:nth-of-type(1) {
background-color: rgb(28, 28, 28);
color: beige;
}
&:nth-of-type(2) {
background-color: rgb(38, 38, 38);
color: beige;
}
&:nth-of-type(3) {
background-color: rgb(48, 48, 48);
color: beige;
}
h1 {
font-family: Arial, Helvetica, sans-serif;
}
}
}
}
解决方案
您描述的行为是默认行为:
默认情况下,滚动捕捉仅在用户停止滚动时才会启动,这意味着他们可以在停止滚动之前跳过几个捕捉点。
为了在每个“页面”(滚动容器的每个子项)处停止滚动,有一个名为 的设置scroll-snap-stop: always
,必须将其应用于滚动容器的子项。但是,这并不适用于所有浏览器。
推荐阅读
- wso2 - WSO2 Identity Server 5.10.0 - 无法实现基于 EmailOTP 的 MFA
- javascript - 无法在 ReactJS 上为模式设置动画
- java - 如何将 DTO 传递给控制器
- laravel - Laravel Carbon 相对于当前时间已经过去了几年
- javascript - 如何在这段代码中创建一个随机对象?
- javascript - NextJS 动态路由 - 是否可以设置路由名称数组?
- arrays - 计数分组单元格excel
- python - 比较pandas python中的行之间的值
- reactjs - 无法将 access_token 传递给 Reactjs 中的端点
- arrays - 如何使用 Angular 10 搜索按键?