使用CSS3的@keyframes動畫

來源:互聯網
上載者:User
CSS3的@keyframes,它可以取代許多網頁動畫映像,Flash動畫,和JAVAScripts。

CSS3的動畫屬性

下面的表格列出了 @keyframes 規則和所有動畫屬性:

瀏覽器支援

表格中的數字表示支援該屬性的第一個瀏覽器版本號碼。

緊跟在 -webkit-, -ms- 或 -moz- 前的數字為支援該首碼屬性的第一個瀏覽器版本號碼。

例子:

@keyframes myfirst{    from {background: red;}    to {background: yellow;}} @-webkit-keyframes myfirst /* Safari 與 Chrome */{    from {background: red;}    to {background: yellow;}}

當在 @keyframes 建立動畫,把它綁定到一個選取器,否則動畫不會有任何效果。

指定至少這兩個CSS3的動畫屬性綁定向一個選取器:

  • 規定動畫的名稱

  • 規定動畫的時間長度

如:

p{    animation: myfirst 5s;    -webkit-animation: myfirst 5s; /* Safari 與 Chrome */}

注意: 您必須定義動畫的名稱和動畫的期間。如果省略的期間,動畫將無法運行,因為預設值是0。

執行個體:注意: 該執行個體在 Internet Explorer 9 及更早 IE 版本是無效的。

p{    width:100px;    height:100px;    background:red;    position:relative;    animation-name:myfirst;    animation-duration:5s;    animation-timing-function:linear;    animation-delay:2s;    animation-iteration-count:infinite;    animation-direction:alternate;    animation-play-state:running;    /* Safari and Chrome: */    -webkit-animation-name:myfirst;    -webkit-animation-duration:5s;    -webkit-animation-timing-function:linear;    -webkit-animation-delay:2s;    -webkit-animation-iteration-count:infinite;    -webkit-animation-direction:alternate;    -webkit-animation-play-state:running;}@keyframes myfirst{    0%   {background:red; left:0px; top:0px;}    25%  {background:yellow; left:200px; top:0px;}    50%  {background:blue; left:200px; top:200px;}    75%  {background:green; left:0px; top:200px;}    100% {background:red; left:0px; top:0px;}}@-webkit-keyframes myfirst /* Safari and Chrome */{    0%   {background:red; left:0px; top:0px;}    25%  {background:yellow; left:200px; top:0px;}    50%  {background:blue; left:200px; top:200px;}    75%  {background:green; left:0px; top:200px;}    100% {background:red; left:0px; top:0px;}}

聯繫我們

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