1、首先引入animate css文件
1 2 3 | < head > < link rel = "stylesheet" href = "animate.min.css" > </ head > |
2、給指定的元素加上指定的動畫樣式名
1 | < div class = "animated bounceOutLeft" ></ div > |
這裏包括兩個class名,第一個是基本的,必須添加的樣式名,任何想實現的元素都得添加這個。第二個是指定的動畫樣式名。
3、如果說想給某個元素動態添加動畫樣式,可以通過jquery來實現:
1 | $( '#yourElement' ).addClass( 'animated bounceOutLeft' ); |
4、當動畫效果執行完成後還可以通過以下代碼添加事件
1 | $( '#yourElement' ).one( 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend' , doSomething); |
你也可以通過 JavaScript 或 jQuery 給元素添加這些 class,比如:
1 2 3 | $( function (){ $( '#jq22' ).addClass( 'animated bounce' ); }); |
有些動畫效果最後會讓元素不可見,比如淡出、向左滑動等等,可能你又需要將 class 刪除,比如:
1 2 3 4 5 6 | $( function (){ $( '#jq22' ).addClass( 'animated bounce' ); setTimeout( function (){ $( '#jq22' ).removeClass( 'bounce' ); }, 1000); }); |
animate.css 的默認設置也許有些時候並不是我們想要的,所以你可以重新設置,比如:
1 2 3 4 5 | #jq22{ animate-duration: 2s; //動畫持續時間 animate-delay: 1s; //動畫延遲時間 animate-iteration-count: 2; //動畫執行次數 } |
原文:http://www.jq22.com/jquery-info819