3D空间转换

6 篇文章 0 订阅
2 篇文章 0 订阅

可以给父元素设置perspective:值;数值一般设为800-1200之间

1.位移 (translate)

语法:transform:translate3d (x,y,z)

<!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>
        body {
            perspective: 800px;
        }
        .box {
            width: 200px;
            height: 200px;
            background-color: burlywood;
            margin: 100px auto;
            transition: all 1s;
        }
        .box:hover {
            transform: translateZ(100px);  
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

X轴向右为正,Y轴向下为正,Z轴是朝向自己的方向为正。

2.旋转(rotated)

语法:transform: rotated3d(x,y,z)

单位为deg(度数)/turn(圈)

<!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>

        .box1 {
            perspective: 800;
            width: 100px;
            height: 100px;
            background-color: #f0f;
            transition: all 1s;
        }

        .box1:hover {
            transform: rotateX(80deg);
        }

        .box2 {
            perspective: 800;
            width: 100px;
            height: 100px;
            background-color: #0F0;
            transition: all 1s;
        }

        .box2:hover {
            transform: rotateY(80deg);
        }

        .box3 {
            perspective: 800;
            width: 100px;
            height: 100px;
            background-color: #00f;
            transition: all 1s;
        }

        .box3:hover {
            transform: rotateZ(80deg);
        }

    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
</body>
</html>

 左手👍拇指朝向是正方向,正数旋转是四指方向,负数相反。

3.缩放(scale)

语法:transform:scale3d (x,y,z)

没有单位,直接填数字,代表的是缩放几倍

<!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>
        body {
            perspective: 800px;
        }

        .box1 {
            width: 200px;
            height: 200px;
            margin: 0 auto;
            background-color: #f00;
            transition: all 1s;
        }

        .box1:hover {
            transform:scaleX(2);
        }

        .box2 {
         width: 200px;
         height: 200px;
         background-color: #00f;
         transition: all 1s;
        }

        .box2:hover {
         transform:scaleY(2);
        }

        .box3 {
         width: 200px;
         height: 200px;
         margin: 0 auto;
         background-color: #f0f;
         transition: all 1s;
        }

        .box3:hover {
         transform:scaleZ(20) rotateX(60deg);
        }

    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
</body>
</html>

Z轴的缩放需要搭配旋转才能看出来

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值