animate.css是一個以CSS3的animation製做的一個動畫效果的CSS集合,裏面預設了不少種經常使用的動畫,且使用很是簡單,本文用來介紹該插件如何使用。css
第一步:html
下載animate.css文件,這個很是容易得到,就很少說了。瀏覽器
第二步:動畫
在你的HTML頁面中導入這個文件,例如:<link rel="stylesheet" href="./animate.min.css">ui
第三步:給你想要添加的動畫效果的元素設置animate.css已經預約義好的css類this
好比:<div class="animated bounceIn">animate.css動畫演示</div>spa
此後,在瀏覽器中運行該頁面,就能看到這個div作出了bounceIn的動畫效果。插件
注意事項:code
下面給出實例: htm
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="animate.css"> <style> .box{ width: 600px; border: 1px solid #ccc; border-radius: 5px; margin: 100px auto; background-color: #eee; overflow: hidden; } .box ul{ width: 200px; float: left; background-color: #ddd; padding: 0; margin: 0; list-style: none; } .box ul li{ font-size: 16px; padding: 10px; text-align: center; border: 1px solid #999; cursor: pointer; } .box div{ width: 400px; /* height: 100%; */ background-color: #eee; border-radius: 5px; float: left; text-align: center; font-size: 16px; } .box div span{ display: block; background-color: pink; padding: 10px 20px; width: 200px; margin: 100px auto; } </style> </head> <body> <div class="box" id="box"> <ul> <li>flash</li> <li>pulse</li> <li>rubberBand</li> <li>shake</li> <li>headShake</li> <li>swing</li> <li>tada</li> <li>wobble</li> <li>jello</li> </ul> <div> <span class="animated">Hello,animate.css!</span> </div> </div> <!-- <span class="animated zoomIn infinite f">Hello,animate.css!</span> --> <script> var box = document.getElementById('box'); var lis = box.getElementsByTagName('li'); var span = box.getElementsByTagName('span')[0]; for(var i = 0; i < lis.length; i++){ lis[i].onclick = function(){ span.className = 'animated ' + this.innerHTML; console.log(span.className); for(var i = 0; i < lis.length; i++){ lis[i].style.backgroundColor = '#ddd'; lis[i].style.color = '#000'; } this.style.backgroundColor = '#444'; this.style.color = '#eee'; } } </script> </body> </html>