css_transform_skew()中的角度问题_动画演示角度变化

reference

skew() - CSS: Cascading Style Sheets | MDN (mozilla.org)

experiment code

这是一个动画,展示了skew()的变化过程(使用了animation来辅助理解)

<!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>
        /* skew learning */
        .box_3_1 {
            /* box-sizing: border-box; */
            width: 300px;
            height: 100px;
            border: solid;
            border-top: solid blue 12px;
            border-left: dashed red 12px;
        }

        .skewerX {
            /* transform: skewX(45deg); */
            animation: skewerX 5s infinite alternate
        }


        .skewerY {
            /* transform: skewY(45deg); */
            animation: skewerY 5s infinite alternate
        }


        .skewer_ani {
            border-radius: 0;
            animation: skewer_frames 10s infinite alternate;

            /* transform: skew(15deg, 15deg);
    transform: skew(85deg, 85deg);
    transform: skew(45deg, 60deg);
    transform: skew(45deg, 30deg); */
        }

        @keyframes skewer_frames {
            from {
                transform: skew(0deg, 0deg);
            }

            /* 两个参数角度和超过90度的时候,容易看出变化规律 */
            to {
                transform: skew(80deg, 40deg);
            }
        }

        @keyframes skewerX {
            from {
                transform: skew(0deg, 0deg);
            }

            to {
                transform: skew(60deg, 0deg);
            }
        }

        @keyframes skewerY {
            from {
                transform: skew(0deg, 0deg);
            }

            to {
                transform: skew(0deg, 60deg);
            }
        }

        div {
            margin: 15%;
        }
    </style>
</head>

<body>
    <section>
        <div class="original">
            <div class="spin ">
            </div>
            <figure class="box_3_1 skewerX">Box X ani</figure>
            <p class="text-align-center">animation: skewerX 5s infinite alternate</p>
            <p>本例子中,我们变化效果相当于操作skewX(),水平边保持和x轴平行,而且矩形高度保持不变</p>
        </div>
        <div class="original">
            <div class="spin ">
            </div>
            <figure class="box_3_1 skewerY">Box Y ani</figure>
            <p class="text-align-center">animation: skewerY 5s infinite alternate</p>
            <p>类似的,垂直边保持和y轴平行,矩形宽度不变</p>
            <p>蓝边和水平轴的夹角最大时刻为设定值:60度</p>
        </div>

        <div class="original">
            <div class="spin ">
            </div>
            <figure class="box_3_1 skewer_ani">Box 4</figure>
            <p class="text-align-center">animation: skewer_frames 10s infinite alternate;</p>
            <p>本例子中,我们看到红蓝边发生了上下相对位置发生了交换</p>
            <p>最终,红边和竖直线Y轴的变化为(0->80度)</p>
            <p>蓝边和水平边(x轴)的夹角从(0->40度)</p>
        </div>
    </section>
</body>

</html>

效果

在这里插入图片描述

skew()和shear mapping函数

skew() - CSS: Cascading Style Sheets | MDN (mozilla.org)

  • This transformation is a shear mapping (transvection)(维基百科链接) that distorts each point within an element by a certain angle in the horizontal and vertical directions.

    • The effect is as if you grabbed each corner of the element and pulled them along a certain angle.
  • The coordinates of each point are modified by a value proportionate to the specified angle and the distance to the origin.

    • Thus, the farther from the origin a point is, the greater the value added to it.
  • image-20220422195019487
  • image-20220422195039910
  • image-20220422195100005
posted @ 2023-09-22 15:42  xuchaoxin1375  阅读(20)  评论(0)    收藏  举报  来源