分享一个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>
相关推荐
后台开发者Ethan21 分钟前
setState组件更新
前端·javascript·react
谙忆102426 分钟前
大文件上传实战:前端分片、断点续传、秒传与并发控制怎么落地
前端
轻动琴弦1 小时前
VoltTool —— 一站式在线开发者工具平台,69+实用工具免费使用
前端·chrome
就叫飞六吧1 小时前
不同站点iframe嵌套种cookie、localstorege.set() 关系
前端
星栈1 小时前
LiveView 怎么测:从组件测试到端到端,我终于不再只敢手点页面了
前端·前端框架·elixir
蜡台1 小时前
uniapp vue2 转 vue3
前端·javascript·uni-app·vue3·vue2
Web4Browser1 小时前
Headless 浏览器自动化适合哪些任务?巡检、截图和提交动作要分级
运维·前端·自动化
用户059540174461 小时前
把前端内存泄漏排查从2小时压到5分钟,我们把它集成进了CI
前端·css
IMPYLH1 小时前
HTML 的 <dd> 元素
前端·html
申君健24864182772022 小时前
Vapor 核心数据结构:Block原理
前端