animate.css 是一個(gè)來自國外的 CSS3 動(dòng)畫庫,它預(yù)設(shè)了抖動(dòng)(shake)、閃爍(flash)、彈跳(bounce)、翻轉(zhuǎn)(flip)、旋轉(zhuǎn)(rotateIn/rotateOut)、淡入淡出(fadeIn/fadeOut)等多達(dá) 60 多種動(dòng)畫效果,幾乎包含了所有常見的動(dòng)畫效果。
雖然借助 animate.css 能夠很方便、快速的制作 CSS3 動(dòng)畫效果,但還是建議看看 animate.css 的代碼,也許你能從中學(xué)到一些東西。
使用方法
1、引入文件
<link rel="stylesheet" href="animate.min.css">
2、HTML 及使用
<div class="animated bounce" id="dowebok"></div>
給元素加上 class 后,刷新頁面,就能看到動(dòng)畫效果了。animated 類似于全局變量,它定義了動(dòng)畫的持續(xù)時(shí)間;bounce 是動(dòng)畫具體的動(dòng)畫效果的名稱,你可以選擇任意的效果。
如果動(dòng)畫是無限播放的,可以添加 class infinite。
你也可以通過 JavaScript 或 jQuery 給元素添加這些 class,比如:
$(function(){ $('#dowebok').addClass('animated bounce'); });
有些動(dòng)畫效果最后會(huì)讓元素不可見,比如淡出、向左滑動(dòng)等等,可能你又需要將 class 刪除,比如:
$(function(){ $('#dowebok').addClass('animated bounce'); setTimeout(function(){ $('#dowebok').removeClass('bounce'); }, 1000); });
animate.css 的默認(rèn)設(shè)置也許有些時(shí)候并不是我們想要的,所以你可以重新設(shè)置,比如:
#dowebok { animate-duration: 2s; //動(dòng)畫持續(xù)時(shí)間 animate-delay: 1s; //動(dòng)畫延遲時(shí)間 animate-iteration-count: 2; //動(dòng)畫執(zhí)行次數(shù) }
注意添加瀏覽器前綴。