css3 過渡和2d變換——回顧

來源:互聯網
上載者:User

標籤:自己的   定義   多少   n+1   translate   負數   ansi   second   縮小   

1.transition
  文法:transition: property duration timing-function delay;
      transition-property 設定過渡效果的css 屬性名稱
        文法: transition-property: none | all | property
            none 沒有屬性會獲得過度效果
            all 所有屬性都將獲得過度效果。
            property 定義應用過度效果css 屬性名稱列表,列表以逗號分割。
            indent 元素屬性名稱
      transition-duration 完成過度效果需要多少秒或者毫秒
        文法:transition-duration:time;
            time 規定完成過渡效果需要的花費的時間。預設值是0, 意味著不會有效果
      transition-timing-function 規定速度效果的速度曲線。
        文法: transition-timing-function: linear|ease|ease-in|ease-out|ease-in-out|cubic-bezier(n,n,n,n);
            linear 規定以相同速度開始至結束的過度效果。
            ease 規定慢速度開始,然後邊快,然後慢速度結束。
            ease-in 規定以慢速度開始的過度效果。
            ease-out 規定以慢速度結束的過度效果。
            ease-in-out 規定以慢速度開始和結束的過渡效果。
            cubic-bezier(n,n,n,n) 在cubic-bezier中定義自己的值,可能的值是0至1之間的數值。
      transition-delay  定義過度效果何時開始
        文法:transititon-delay: time;
          time 規定在過渡效果開始之前需要等待的時間。

     樣本:
      <style>
          .box{width:100px;height:100px;background:red; transition:width 1s ;}
          .box:hover{ background:blue;width:300px;height:150px;}
      </style>
      <div class="box"></div>
      結果:

        

     樣本:(貝茲路徑)
        <style>
          .box{width:100px;height:100px;background:red; transition:5swidth cubic-bezier(0.145,1.295,0.000,1.610);}
          .box:hover{width:500px;}
        </style>
        <div class="box"></div>
    結果:

        

    樣本:(多種變化一起寫)
      <style>
        .box{width:100px;height:100px;background:red; transition:1swidth,2s height,3s background;}
        .box:hover{width:300px;height:150px;background:blue;}
      </style>
      <div class="box"></div>
    結果:

      

2.transform
    字母上就是變形,改變的意思,在css3中transform主要包括一下幾種,旋轉rotate,扭曲skew,縮放scale和移動translate 以及矩陣變形matrix 
        文法:transform : none | <transform-function> [ <transform-function> ]*
          也就是: transform: rotate | scale | skew | translate |matrix;

            none表示不進怎麼變換;<transform=function>表示一個或者多個變換函數,以空格分開;
            rotate,scale,translate 三種,但這裡需要提醒大家的,以往我們疊加效果都是用逗號(“,”)隔開,

            但transform中使用多個屬性時卻需要有空格隔開。大家記住了是空格隔開。

          旋轉rotate
            通過指定的角度參數對原元素指定一個2D rotation(2D 旋轉),需先有transform-origin屬性的定義。
                transform-origin定義的是旋轉的基點,其中angle是指旋轉角度
            如果設定的值為正數表示順時針旋轉,如果設定的值為負數,則表示逆時針旋轉。
              如:transform:rotate(30deg):
          移動translate
            移動translate我們分為三種情況:translate(x,y)水平方向和垂直方向同時移動(也就是X軸和Y軸同時移動);translateX(x)僅水平方向移動(X軸移動translateY(Y)僅垂直方向移動(Y軸移動)

          縮放scale
           縮放scale和移動translate是極其相似,他也具有三種情況:scale(x,y)使元素水平方向和垂直方向同時縮放(也就是X軸和Y軸同時縮放);scaleX(x)元素僅水平方向縮放(X軸縮放);
              scaleY(y)元素僅垂直方向縮放(Y軸縮放),但它們具有相同的縮放中心點和基數,
            其中心點就是元素的中心位置,縮放基數為1,如果其值大於1元素就放大,反之其值小於1,元素縮小。

          扭曲skew
             扭曲skew和translate,secale skew(x,y)使元素在水平和垂直方向同時扭曲(X軸和Y軸同時按一定的角度值進行扭曲變形);skewX(x)僅使元素在水平方向扭曲變形(X軸扭曲變形);

              skewY(y)僅使元素在垂直方向扭曲變形(Y軸扭曲變形)

          矩陣matrix
              matrix(<number>, <number>, <number>, <number>, <number>,
                <number>) 以一個含六值的(a,b,c,d,e,f)
             變換矩陣的形式指定一個2D變換,相當於直接應用一個[a b c d e f]變換矩陣。就是基於水平方向(X軸)和垂
              直方向(Y軸)重新置放元素,改變元素的基點 transform-origin他的主要作用就是讓我們在進行transform動作之前可以改變元素的基點位置,
              因為我們元素預設基點就是其中心位置,換句話說我們沒有使用transform-origin改變元素基點位置的情況下,
              transform進行的rotate,translate,scale,skew,matrix等操作都是以元素自己中心位置進行變化的。

        樣本: (旋轉)
          <style>
            .box{width:100px;height:100px;background:red;margin:100px auto 0; transition:2s;}
            .box:hover { -webkit-transform:rotate(45deg);}
          </style>
          <div class="box">111</div>
        結果:

          

        樣本:(位移)
          <style>
            .box{width:100px;height:100px;background:red;margin:100px auto 0; transition:2s;}
            .box:hover{-webkit-transform:translate(-100px,200px);}
          </style>
          <div class="box">111</div>
        結果:元素的位置發生變化。

        樣本:(縮放)
          <style>
            .box{width:100px;height:100px;background:red;margin:100px auto 0; transition:2s;}
            .box:hover{webkit-transform:scale(2);}
          </style>
          <div class="box">111</div>
        結果:

          

        樣本:(扭曲)
            <style>
              .box{width:80px;height:80px;background:red;margin:100px auto 0; transition:2s;}
              .box:hover{-webkit-transform:skewX(45deg);}
            </style>
            <div class="box">111</div>
        結果:

          

        樣本:(矩陣)
            <style>
                .box{width:80px;height:80px;background:red;margin:100px auto 0; transition:2s;}
                .box:hover{-webkit-transform:matrix(0.5,0.38,-0.38,2,0,0);}
            </style>
            <div class="box">111</div>
        結果:

          

        demo 樣本:
          <style id="css">
              #wrap{width:200px;height:200px;border:2px solid #000; margin:100px auto; border-radius:50%; position:relative;}
              #wrap ul{margin:0;padding:0;height:200px; position:relative; list-style:none;}
              #wrap ul li{ width:2px;height:6px;background:#000; position:absolute;left:99px;top:0; -webkit-transform-origin:center 100px;}
              #wrap ul li:nth-of-type(5n+1){ height:12px;}
              #hour{width:6px;height:45px;background:#000; position:absolute;left:97px;top:55px;-webkit-transform-origin:bottom;}
              #min{width:4px;height:65px;background:#999; position:absolute;left:98px;top:35px;-webkit-transform-origin:bottom;}
              #sec{width:2px;height:80px;background:red; position:absolute;left:99px;top:20px;-webkit-transform-origin:bottom;}
              .ico{width:20px;height:20px;background:#000; border-radius:50%; position:absolute;left:90px;top:90px;}
          </style>
          <div id="wrap">
            <ul id="list">
            </ul>
            <div id="hour"></div>
            <div id="min"></div>
            <div id="sec"></div>
            <div class="ico"></div>
          </div>
          <script>
              var oList=document.getElementById("list");
              var oCss=document.getElementById("css");
              var oHour=document.getElementById("hour");
              var oMin=document.getElementById("min");
              var oSec=document.getElementById("sec");
              var aLi="";
              var sCss="";
              for(var i=0;i<60;i++)
                {
                  sCss+="#wrap ul li:nth-of-type("+(i+1)+"){ -webkit-transform:rotate("+i*6+"deg);}";
                  aLi+="<li></li>"
                }
              oList.innerHTML=aLi;
              oCss.innerHTML+=sCss;
              toTime();
              setInterval(toTime,1000);
              function toTime()
                  {
                    var oDate=new Date();
                    var iSec=oDate.getSeconds();
                    var iMin=oDate.getMinutes()+iSec/60;
                    var iHour=oDate.getHours()+iMin/60;
                    oSec.style.WebkitTransform="rotate("+iSec*6+"deg)";
                    oMin.style.WebkitTransform="rotate("+iMin*6+"deg)";
                    oHour.style.WebkitTransform="rotate("+iHour*30+"deg)";
                };
            </script>
          結果:

          

 

css3 過渡和2d變換——回顧

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.