CSS3入門之2D、3D、過度、動畫

2D 3D 過度 動畫

  • 2D效果 主要是平面的一些常規(guī)操作 transform屬性
  1. 移動 transform: translate(20px,30px); 水平移動 和 垂直移動 水平沿X軸方向進行 垂直沿Y軸方向進行
    屬性值可以為負(fù)值 水平方向負(fù)值往左移動 垂直方向負(fù)值往上移動
  2. 縮放 transform: scale(2, 4); 同樣也是水平 和 垂直方向 的放大縮小
  3. 旋轉(zhuǎn) transform: rotate(90deg); 默認(rèn)以中心坐標(biāo)旋轉(zhuǎn) 坐標(biāo)點也可以指定 指定坐標(biāo)點的屬性 transform-origin: 50px 100px; 或者是方位值 可以是具體的像素值
  4. 傾斜 transform: skew(20deg, 30deg); 同樣也是水平 和 垂直方向
  • 3D 主要是有立體感 實現(xiàn)一些炫酷的效果
  1. 旋轉(zhuǎn) transform: rotateX(50deg); transform: rotateY(50deg);等
  • 過度 從一種樣式逐漸改變到另一種效果 需要滿足兩個條件
    1、添加到CSS屬性上 transition: width 2s, height 2s, transform 2s; 作用于寬度、高度、2D效果上等
    2、設(shè)置效果時長
  • 動畫 ->變形 過度 動畫 通過animation屬性實現(xiàn) 需要滿足兩個條件
    1、動畫名稱
    2、動畫時長
    格式:
    標(biāo)簽 {
    /* 使用動畫 anim 時長 3秒 */
    animation: anim 3s;
    }
    @keyframes anim{
    屬性:值;
    }
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        .box1 {
            width: 100px;
            height: 60px;
            background-color: red;
            /* 移動 transform */
            /* 沿X軸移動 往右移動20像素 */
            /*transform: translateX(20px);*/
            /* 沿X軸移動往左移動50像素 */
            /*transform: translateX(-50px);*/
            /* 沿Y軸移動 往下移動50像素 */
            /*transform: translateY(50px);*/
            /* 沿Y軸移動 往上移動50像素 */
            /*transform: translateY(-50px);*/
            /* 沿X軸移動 往右移動20像素 沿Y軸移動 往下移動30像素 */
            /*transform: translate(20px,30px);*/

        }

        .box1 {
            /* 旋轉(zhuǎn) */
            /*margin-left: 50px;
            margin-top: 50px;*/
            /* 順時針旋轉(zhuǎn)90度 */
            /*transform: rotate(90deg);
            -webkit-transform: rotate(90deg);
            -moz-transform: rotate(90deg);
            -ms-transform: rotate(90deg);
            -o-transform: rotate(90deg);*/
            /* 3D旋轉(zhuǎn) */
            /*transform: rotateX(50deg);
            -webkit-transform: rotateX(50deg);*/
            /*transform: rotateY(50deg);
            -webkit-transform: rotateY(50deg);*/
        }

        .box1 {
            /* 縮放 */
            /* 放大原來的倍數(shù) 不能是具體的像素值 */
            /*transform: scale(2, 4);*//*水平放大2倍 垂直方向放大4倍*/
            /* X軸放大2倍 */
            /*transform: scaleX(2);*/
            /* Y軸放大2倍 */
            /*transform: scaleY(2);
            -webkit-transform: scaleY(2);*/
        }

        .box1 {
            /* 傾斜 */
            /*transform: skew(20deg, 30deg);*//* X軸傾斜20度 Y軸傾斜30度 */
            /* X軸傾斜20度 Y軸保持不變 */
            /*transform: skewX(20deg);*/
            /* Y軸傾斜20度 X軸保持不變 */
            /*transform: skewY(20deg);*/
            /* 矩陣 */
            /*transform: matrix(1,0,0,1,30,30);*/
            /* 基于坐標(biāo)點 進行旋轉(zhuǎn) 其它屬性都可以配合使用 */
            /*-webkit-transform-origin: 50px 100px;*/ /* 原點變化為 50 100坐標(biāo)點 */
            /*transform: rotate(30deg);*/
        }

        .box1 {
            /* 過度 從一種樣式逐漸改變到另一種效果 滿足條件*/
            /* 1. 添加到CSS屬性上 */
            /* 2. 效果時長 */
            /* 鼠標(biāo)懸浮上寬高從100px到300px 過度時間2秒 旋轉(zhuǎn)也是*/
            transition: width 2s, height 2s, transform 2s;
        }

        .box1:hover {
            width: 300px;
            height: 300px;
            transform: rotate(50deg);
            -webkit-transform: rotate(50deg);
        }

        .box2 {
            /* 動畫 滿足條件 */
            /* 1. 動畫名稱 */
            /* 2. 動畫時長 */
            width: 100px;
            height: 100px;
            background-color: blue;
            position: relative;
            animation: anim 3s;
            -webkit-animation: anim 5s;
        }
        @keyframes anim{
            /*from {
                background-color: #333;
            }
            to {
                background-color: yellow;
            }*/
            0% {
                background-color: #333;
                top: 0px;
                left: 0px;
            }
            25% {
                background-color: #666;
                top: 0px;
                left: 100px;
            }
            50% {
                background-color: #999;
                top: 100px;
                left: 100px;
            }
            75% {
                background-color: #0f0;
                top: 100px;
                left: 0px;
            }
            100% {
                background-color: #00f;
                top: 00px;
                left: 0px;
            }
        }

        @-webkit-keyframes anim{
            /*from {
                background-color: #333;
            }
            to {
                background-color: yellow;
            }*/
            0% {
                background-color: #333;
                top: 0px;
                left: 0px;
            }
            25% {
                background-color: #666;
                top: 0px;
                left: 100px;
            }
            50% {
                background-color: #999;
                top: 100px;
                left: 100px;
            }
            75% {
                background-color: #0f0;
                top: 100px;
                left: 0px;
            }
            100% {
                background-color: #00f;
                top: 00px;
                left: 0px;
            }
        }
        /*.box2:hover {
            animation: anim 3s;
            -webkit-animation: anim 5s;
        }*/

    </style>
</head>
<body>

    <!-- 移動 旋轉(zhuǎn) 縮放 傾斜 -->

    <div class="box1">盒子</div>

    <div class="box2">盒子</div>

</body>
</html>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容