分享一个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>
相关推荐
前端Hardy12 小时前
HTML&CSS:有趣的漂流瓶
前端·javascript·css
前端Hardy12 小时前
HTML&CSS :惊艳 UI 必备!卡片堆叠动画
前端·javascript·css
无羡仙12 小时前
替代 Object.freeze 的精准只读模式
前端·javascript
web前端12312 小时前
Java客户端开发指南 - 与Web开发对比分析
前端
龙在天12 小时前
前端 9大 设计模式
前端
搞个锤子哟12 小时前
网站页面放大缩小带来的问题
前端
hj5914_前端新手12 小时前
React 基础 - useState、useContext/createContext
前端·react.js
半花13 小时前
【Vue】defineProps、defineEmits 和 defineExpose
前端·vue.js
霍格沃兹_测试13 小时前
软件测试 | 测试开发 | H5页面多端兼容测试与监控
前端
toooooop813 小时前
本地开发环境webScoket调试,保存html即用
前端·css·websocket