前端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轴

相关推荐
lpfasd12314 小时前
pywebview与Electron
前端·javascript·electron
行走的陀螺仪14 小时前
Claude Code 从入门到实战(一):安装、登录与第一个Vue项目
前端·javascript·vue.js
梦曦i14 小时前
0.8.2 新增 backFallback 配置,无 tabbar 页返回无忧
前端·uni-app x
vipxieliang14 小时前
解构赋值与展开运算符:现代 JS 提效技巧
javascript
Amos_Web14 小时前
Rspack 源码解析(三十四):rspack_hook 与宏系统如何用过程宏生成异步 Hook 与插件
前端
恋猫de小郭14 小时前
感人,Flutter 居然有了一个超实用提案,期待落地
android·前端·flutter
wordbaby15 小时前
为什么 Apifox 能调通,浏览器却报跨域?一次“CORS Error + 403”联调排坑实录
前端
2603_9658966215 小时前
JavaScript 原型与原型链
开发语言·前端·javascript
Amos_Web15 小时前
通过 Rspack 源码学 Rust(四):用 `Option<T>` 表达“查询可能没有结果”
前端
朋友圈自动点赞工具15 小时前
Ruby方法查找:对象不存方法
开发语言·前端·ruby·科技资讯