animate.css動畫庫簡介
Animate.css是由Dan Eden的Daniel Eden使用CSS3的animation制作的動畫效果的CSS集合。
它預設了抖動(shake)、閃爍(flash)、彈跳(bounce)、翻轉(flip)、旋轉(rotateIn/rotateOut)、淡入淡出(fadeIn/fadeOut)等多達 60 多種動畫效果,幾乎包含了所有常見的動畫效果。換句話說:Animate.css就是一大堆的很酷,很有趣,而且很炫又能跨浏覽器的動畫效果樣式集錦,可以直接使用到項目中。
animate.css動畫庫的浏覽器相容性
隻相容支援 CSS3 animate 屬性的浏覽器,他們分别是:IE10+、Firefox、Chrome、Opera、Safari。
使用方法
1、引入檔案 animate.css動畫庫下載下傳位址
<link rel="stylesheet" href="animate.min.css">
//注:最好不要使用百度靜态資源庫的animate.css,可能版本沒來得及更新部分功能無法使用。
2、HTML 及使用
<div class="animated bounce" id="hepai"></div>
給元素加上 class 後,重新整理頁面,就能看到動畫效果了。animated 類似于全局變量,它定義了動畫的持續時間;bounce 是動畫具體的動畫效果的名稱,你可以選擇任意的效果。
如果你要使用永續動畫,可以在class中加上infinite(如果你用的是百度靜态資源庫的animate.css,這個好像就實作不了了);如:
<div class="animated bounce infinite" id="hepai"></div>
你也可以通過 JavaScript 或 jQuery 給元素添加這些 class,比如:
$(function(){
$('#hepai').addClass('animated bounce');
});
有些動畫效果最後會讓元素不可見,比如淡出、向左滑動等等,可能你又需要将 class 删除,比如:
$(function(){
$('#hepai').addClass('animated bounce');
setTimeout(function(){
$('#dowebok').removeClass('bounce');
}, 1000);
});
#hepai {
-webkit-animation-duration:2s;
-webkit-animation-delay:1s;
-webkit-animation-iteration-count:2;
}