分享一个css的吸附效果scroll-snap-type

html 复制代码
<!DOCTYPE html>

<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>
        
    </title>
   
    <meta charset="UTF-8" />
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no" />


 
</head>
<style>
    .box{
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        position: fixed;
        overflow-y: scroll;
        /* scroll-snap-type: y mandatory; */
        scroll-snap-type: y proximity;
    }
    .item{
        position: relative;
        min-height: 100vh;
        scroll-snap-align: start;
        scroll-snap-stop: always;
    }
</style>
<body>
    <div class="box">
        <div class="item" style="background-color: black;"></div>
        <div class="item" style="background-color: #e0e0e0;height: 150vh;"><p style="position: absolute;top: 0;">头部文字</p><p style="position: absolute;bottom: 0;">底部文字</p></div>
        <div class="item" style="background-color: #999999;height: 120vh;"></div>
    </div>
</body>

</html>
相关推荐
长安城没有风几秒前
更适合后端宝宝的前端三件套之HTML
前端·html
伍哥的传说几秒前
Vue3 Anime.js超级炫酷的网页动画库详解
开发语言·前端·javascript·vue.js·vue·ecmascript·vue3
欢乐小v22 分钟前
elementui-admin构建
前端·javascript·elementui
霸道流氓气质1 小时前
Vue中使用vue-3d-model实现加载3D模型预览展示
前端·javascript·vue.js
溜达溜达就好1 小时前
ubuntu22 npm install electron --save-dev 失败
前端·electron·npm
慧一居士1 小时前
Axios 完整功能介绍和完整示例演示
前端
晨岳1 小时前
web开发-CSS/JS
前端·javascript·css
22:30Plane-Moon1 小时前
前端之CSS
前端·css
半生过往1 小时前
前端上传 pdf 文件 ,前端自己解析出来 生成界面 然后支持编辑
前端·pdf