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

相关推荐
白中白121384 小时前
杂七杂八补充系列
开发语言·前端·javascript
Xingxing?!4 小时前
Vue2 微信小程序:页面间传递数组
前端·vue.js·uni-app
肉肉不吃 肉4 小时前
代理服务的原理,及Vite 中具体实现方法
前端·vue.js
前端小D4 小时前
作用域/闭包
前端·javascript
前端 贾公子4 小时前
@uni-helper 社区:让 uni-app 拥抱 ESM 时代
开发语言·前端·javascript
大卡拉米4 小时前
ClaudeCode安装及使用
前端·学习
豆豆4 小时前
PageAdmin CMS模板开发详解:HTML转CMS系统的10个核心步骤
前端·html·cms·网站建设·网站制作·自助建站·网站管理系统
lemon_yyds4 小时前
vue 2 升级vue3 : element ui 校验红色高亮失去效果
前端·element
真夜4 小时前
又遇到生产与开发环境结果不一致问题。。。
前端·javascript·http
lemon_yyds4 小时前
vue2升级vue3:图片点击预览出现样式错乱
前端