两句css代码实现全屏滚动效果-demo案例
效果
两句css代码实现全屏滚动效果
html代码
<body>
<div class="container">
<section>
<h3>第一屏内容</h3>
<p>
在父容器上使用scroll-snap-type 属性 <br>
第一个参数y 是y轴捕捉位置 <br>
mandatory 超过距离则自动滚动到下一个容器 <br>
scroll-snap-type:y mandatory <br>
在需要滚动的容器上使用 scroll-snap-align 属性 <br>
start 开始部分 end 结束部分 center 中间部分 <br>
scroll-snap-align:start; <br>
</p>
</section>
<section>
<h3>第二屏内容</h3>
<p>
在父容器上使用scroll-snap-type 属性 <br>
第一个参数y 是y轴捕捉位置 <br>
mandatory 超过距离则自动滚动到下一个容器 <br>
scroll-snap-type :y mandatory <br>
在需要滚动的容器上使用 scroll-snap-align 属性 <br>
start 开始部分 end 结束部分 center 中间部分 <br>
scroll-snap-align:start; <br>
</p>
</section>
<section>
<h3>第三屏内容</h3>
<p>
在父容器上使用scroll-snap-type 属性 <br>
第一个参数y 是y轴捕捉位置 <br>
mandatory 超过距离则自动滚动到下一个容器 <br>
scroll-snap-type :y mandatory <br>
在需要滚动的容器上使用 scroll-snap-align 属性 <br>
start 开始部分 end 结束部分 center 中间部分 <br>
scroll-snap-align:start; <br>
</p>
</section>
</div>
</body>
css代码
<style>
body {
margin: 0;
}
.container {
height: 100vh;
overflow-y: scroll;
scroll-snap-type: y mandatory;
}
section {
box-sizing: border-box;
padding: 112px;
height: 100%;
color: white;
scroll-snap-align: start;
}
section:nth-of-type(1) {
background-color: #60af15;
}
section:nth-of-type(2) {
background-color: #158baf;
}
section:nth-of-type(3) {
background-color: #af1581;
}
</style>
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634037.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现