前端3d动画-----平移 transform: translate3d()

必须加这个属性:transform-style: preserve-3d;

perspective: 900px; 设置了景深才能感到近大远小的感觉

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">
    <title>Document</title>
    <style>
        .box{
            width: 500px;
            height: 500px;
            border: 5px solid black;
            transform-style: preserve-3d;
            /* 
            必加transform-style: preserve-3d; 
            默认是flat:2d;
            */
            position: relative;
            margin: 0 auto;
            /* transform: rotateY(30deg);*/
             
            perspective: 900px;
            /* 设置景深 */
        }
        .center{
            position:absolute;
            width: 200px;
            height: 200px;
            background: red;
            left: 50%;
            top: 50%;
            margin-left: -100px;
            margin-top: -100px;
            transition: all 3s;
        }
        .box:hover .center{
            /* transform: translateZ(800px); */
            transform: translate3d(0,0,200px);
            /* 正值朝前,负值朝后 */
        }

    </style>
</head>
<body>
    <div class="box">
        <div class="center"></div>
    </div>
</body>
</html>

transform: translateZ(80px); 等于transform: translate3d(0,0,80px);,里面的参数对应x,y,z轴

相关推荐
徐小夕3 小时前
我用 AI 撸了个开源"万能预览器":浏览器直接打开 Office、CAD 和 3D 模型
前端·vue.js·github
小码哥_常4 小时前
Flutter Android 延迟加载代码指南:提升应用性能的关键
前端
这是个栗子4 小时前
TypeScript(三)
前端·javascript·typescript·react
kvo7f2JTy4 小时前
基于机器学习算法的web入侵检测系统设计与实现
前端·算法·机器学习
北风toto4 小时前
前端CSS样式详细笔记
前端·css·笔记
nanfeiyan4 小时前
git commit
前端
前端精髓7 小时前
移除 Effect 依赖
前端·javascript·react.js
码云之上7 小时前
从一个截图函数到一个 npm 包——pdf-snapshot 的诞生记
前端·node.js·github
码事漫谈7 小时前
AI提效,到底能强到什么程度?
前端·后端
IT_陈寒7 小时前
React hooks依赖数组这个坑差点把我埋了
前端·人工智能·后端