css3整理(二)

來源:互聯網
上載者:User

標籤:

css3邊框

boder-radius

兩個參數:左上右下, 右上左下(具體數值就是遠的半徑)

四個參數:左上 右上 右下 左下 (順時針)

box-shadow

參數:水平距離  垂直距離  模糊邊框  模糊半徑  顏色 是否在邊界內部(inset/預設為outset)

 

css3背景

background-size:背景大小

background-size : contain;

 

background-size : cover;

background-size : 100% 100%;

 

background-orgin : 背景位置

background-orgin : border-box;

background-orgin : padding-box;

background-orgin : content-box;

這裡我都給了padding值,比較一下,可以得出:

值為border-box時,border在content中;

值為content-box時,padding在content中;

值為padding-box時,padding在border和content中間。

 

css3變形

transform:

translate( ) 位移移動

transform的translate位移操作
            跟相對定位類似,不脫離文檔流,而且也不影響其他元素的位置
            translate位移
                兩個參數 : x , y, z
                translateX()   translateY() translateZ();

css

.stage {
                width: 300px;
                height: 300px;
                margin: 20px;
                float: left;
                position:relative;
                background: url(img/bg.jpg);
                perspective: 800px;
                /*視距, perspective 給要變形元素的父元素加上這個屬性
                 * 眼睛跟螢幕的距離*/

               這裡給s2 img2 在z軸上移動了400px,所以給一個800px的視距能有一個遠近的效果
            }
            .stage .container{
                position: absolute;
                left: 50%;
                top:50%;
                margin-left: -35px;
                margin-top: -50px;
            }
       
            .stage .container img{
                position: absolute;
                left:0px;
                top:0px;
            }
           
            .stage .container img:nth-child(1){
                opacity: 0.5;
            }
           
           
            .s1 .container img:nth-child(2){
                transform: translate(100px,100px);
                /*transform: translateY(-100px);*/
                /*transform: translateX(-100px);*/
            }
           
            .s2 .container img:nth-child(2){
                transform: translateZ(400px); /*視距感覺圖片變大*/
                /*transform: translateZ(-400px);*//*視距感覺圖片變小*/
            }       

 

html

<div class="stage s1">
            <div class="container">
                <img src="img/cardKingClub.png" width="70" height="100" />
                <img src="img/cardKingClub.png" width="70" height="100" />
            </div>

</div>
<div class="stage s2">
            <div class="container">
                <img src="img/cardKingClub.png" width="70" height="100" />
                <img src="img/cardKingClub.png" width="70" height="100" />
            </div>

</div>

scale( ) 大小縮放

這個原理和背景圖片大小是一樣的,比較好理解。

rotate( ) 旋轉

transform: rotateX(40deg);

transform: rotateY(-40deg);

補充:   
               (1)如果rotate 中值是正數  就是 順時針 旋轉度數 , 如果是負數就是逆時針旋轉度數
               (2)如果 rotate(45deg) ===  rotateZ(45deg)
               (3)rotate3d(0,1,1,30deg) 標示你是否希望沿著該軸旋轉,是為1,不是為0,最後一個標示旋轉的角度。
               (4)預設以中心點旋轉,transform-origin : 水平 垂直;  這樣設定參照的中心點

skew( ) 傾斜

這玩意,沒怎麼見過,就動手試了一下 :)

transform: skewX(30deg);

transform: skewY(-30deg);

transform: skew(30deg,30deg);

補:

perspective 視距 景深
perspective-origin 屬性指定了觀察者關注的位置
transform-style (preserve-3d) 建立3D空間
backface-visibility 隱藏背面

css3過渡

transition:

參數:屬性   期間   延遲時間   運動形式

拆分寫為:

transition-property
transition-duration
transition-delay負數的是提前執行
transition-timing-function(linear, ease, ease-in, ease-out,ease-in-out) 加速度的形式

對應的事件:

        <div id="div1">
            <div id="div2"></div>

        </div>
        <script>
            var oDiv2 = document.getElementById(‘div2‘);

            oDiv2.addEventListener(‘transitionend‘, function(ev) {
                console.log(ev);
                if(ev.propertyName =="transform"){
                    oDiv2.style.background = "yellow";
                }
            }, false);


            //transitionend : 當css3過渡時間結束的時候,就觸發這個事件
        </script>

css3動畫

animation

animation-direction   運動執行的方式
animation-play-state 運動執行狀態  pasted 和 running
animation-fill-mode  
     forwards 當動畫完成以後,保持最後一個屬性

     backwards 動畫顯示之前,應用該屬性
@keyframes   有三種寫法  1.from to  2個關鍵字

                                       2.10% 50% 100%   多個百分比值來執行固定時間的動畫

                                       3.animation: steps()   針對整合好的spirt圖通過固定頻率形成動畫

對應的事件:

<div id="div1"></div>

<script>
    var oDiv = document.getElementById(‘div1‘);

    oDiv.addEventListener(‘animationstart‘, function() {
        console.log("動畫開始");
    }, false);
    oDiv.addEventListener(‘animationend‘, function() {
        console.log("動畫結束");
    }, false);
    oDiv.addEventListener(‘animationiteration‘, function(ev) {
        console.log(ev.elapsedTime); //總時間(每一次時間的累加和)
    }, false);

    //animationstart : 當css3的animation開始的時候觸發的事件
    //animationend : 當css3的animation結束的時候觸發的事件
    //animationiteration : 當css3的animation多次的時候觸發的事件(每走一次就觸發一下) 總次數 是 n-1  , n 是動畫執行的次數
</script>

 

動畫執行個體:

不會gif,先用靜態代替一下--

html

* {
            margin: 0;
            padding: 0;
        }
       
        ul {
            margin: 100px;
        }
       
        li {
            list-style: none;
        }
       
        li {
            width: 5px;
            height: 30px;
            background: green;
            float: left;
            margin-right: 5px;
            animation: runLine 2s infinite linear;
        }
       
        @keyframes runLine{
            0%{
                transform: scaleY)(1);
            }
            50%{
                transform: scaleY(0.5);
            }
            100%{
                transform: scaleY(1);
            }
        }
        ul li:nth-of-type(1){
            animation-delay: 0;
        }
        ul li:nth-of-type(2){
            animation-delay: -.2s;
        }
        ul li:nth-of-type(3){
            animation-delay: -.4s;
        }
        ul li:nth-of-type(4){
            animation-delay: -.6s;
        }
        ul li:nth-of-type(5){
            animation-delay: -.8s;
        }
        ul li:nth-of-type(6){
            animation-delay: -1s;
        }

html

<ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>

</ul>

 

最後放rotate座標軸和skew座標軸、還有transition的運動形式吧。

     

css3整理(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.