CSS3實現動畫的兩種方式

來源:互聯網
上載者:User

標籤:log   vps   target   pyw   animation   name   ram   alternate   and   

1、設定transition設定過渡,添加transform設定形狀,形成動畫效果,如下:

.divadd { transition: All 0.4s ease-in-out;         -webkit-transition: All 0.4s ease-in-out;         -moz-transition: All 0.4s ease-in-out;         -o-transition: All 0.4s ease-in-out; transform:rotate(360deg);-ms-transform:rotate(360deg); /* IE 9 */-webkit-transform:rotate(360deg); /* Safari and Chrome */}

  此種方式比較小眾,不易控制

2、添加animation屬性,設定動畫效果,如下:

.a1 {position: absolute;animation: a1 3s;opacity: 0}@keyframes a1 {0% {left: 10px;opacity: 0}30% {left: 60px;background-color: pink;font-size:23px;opacity: 1}90% {left: 100px;background-color: red;opacity: 1}100% {left: 10px;opacity: 0}} 

 

以上百分比後的方括弧內可以添加各種屬性值,比如transform ratote、left。。。。。。添加left top等定位不要忘記設定position absolute。

所有屬性有:

    animation-name: myfirst;  //動畫名稱,用於animation引用    animation-duration: 5s;  //動畫時間長度,    animation-timing-function: linear;    animation-delay: 2s;    animation-iteration-count: infinite;    animation-direction: alternate;    animation-play-state: running;
animation-fill-mode
設定動畫結束後的狀態
none:預設值。不設定對象動畫之外的狀態,DOM未進行動畫前狀態
forwards:設定對象狀態為動畫結束時的狀態,100%或to時,當設定animation-direcdtion為reverse時動畫結束後顯示為keyframes第一幀
backwards:設定對象狀態為動畫開始時的狀態,(測試顯示DOM未進行動畫前狀態)
both:設定對象狀態為動畫結束或開始的狀態,結束時狀態優先


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.