天天看點

css_transform_skew()中的角度問題_動畫示範角度變化

文章目錄

  • ​​reference​​
  • ​​experiment code​​
  • ​​效果​​
  • ​​skew()和shear mapping函數​​

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>      

效果

css_transform_skew()中的角度問題_動畫示範角度變化

skew()和shear mapping函數

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

  • This transformation is ashear mapping (​​transvection​​)(維基百科連結) that distorts each point within an element by a certain angle in the horizontal and vertical directions.
  • The effect isas if you grabbed each corner of the element and pulled themalonga certain angle.
  • The coordinates of each point are modified bya value proportionate to the specified angle and the distance to the origin.
  • Thus, thefartherfrom the origin a point is,the greater the value added to it.
  • css_transform_skew()中的角度問題_動畫示範角度變化
  • css_transform_skew()中的角度問題_動畫示範角度變化
  • css_transform_skew()中的角度問題_動畫示範角度變化