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

相关推荐
油丶酸萝卜别吃4 小时前
utils.js 说明文档
开发语言·javascript·ecmascript
zyplayer-doc7 小时前
VuePress类静态文档站和动态知识库怎么选:两种技术路线的适用场景
javascript·人工智能·后端·安全·智能手机
紫禁玄科8 小时前
Shai-Hulud:npm生态的自我复制蠕虫风暴
前端·npm·node.js
东风破_8 小时前
后端API没写好,前端难道干等着吗?
前端
百变梦仔8 小时前
从读项目到纠偏交付:我把 Codex 前端任务闭环升级成了第二版
前端
用户938515635079 小时前
从前后端分离到前端接口工程:React + MockJS + Vite 解析
前端·后端·全栈
用户938515635079 小时前
从零在浏览器里跑 DeepSeek-R1:WebGPU + Transformers.js 全链路实战(三)
前端·react.js·typescript
excel9 小时前
当前端行情变差,我们为什么还要坚持?
前端
鸿是江边鸟,曾是心上人9 小时前
快速搭建HTTPS本地开发环境
前端
To_OC10 小时前
写了 5 个表单 Demo 后,我终于彻底搞懂了 React 受控与非受控组件
前端·react.js·前端框架