CSS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | /* bounce */ .bounce { /* http://anicollection.github.io/#/attention_seekers/bounce */ animation-duration: 1 s; animation-fill-mode: both ; animation-name: bounce; transform-origin: center bottom } @keyframes bounce { 0% , 100% , 20% , 53% , 80% { transition-timing-function: cubic-bezier( 0.215 , . 61 , . 355 , 1 ); transform: translate 3 d( 0 , 0 , 0 ) } 40% , 43% { transition-timing-function: cubic-bezier( 0.755 , . 050 , . 855 , . 060 ); transform: translate 3 d( 0 , -30px , 0 ) } 70% { transition-timing-function: cubic-bezier( 0.755 , . 050 , . 855 , . 060 ); transform: translate 3 d( 0 , -15px , 0 ) } 90% { transform: translate 3 d( 0 , -4px , 0 ) } } /* rubberBand */ .rubberBand { /* http://anicollection.github.io/#/attention_seekers/rubberBand */ animation-duration: 1 s; animation-fill-mode: both ; animation-name: rubberBand } @keyframes rubberBand { 0% { transform: scale 3 d( 1 , 1 , 1 ) } 30% { transform: scale 3 d( 1.25 , . 75 , 1 ) } 40% { transform: scale 3 d( 0.75 , 1.25 , 1 ) } 50% { transform: scale 3 d( 1.15 , . 85 , 1 ) } 65% { transform: scale 3 d(. 95 , 1.05 , 1 ) } 75% { transform: scale 3 d( 1.05 , . 95 , 1 ) } 100% { transform: scale 3 d( 1 , 1 , 1 ) } } /* tada */ .tada { /* http://anicollection.github.io/#/attention_seekers/tada */ animation-duration: 1 s; animation-fill-mode: both ; animation-name: tada } @keyframes tada { 0% { transform: scale 3 d( 1 , 1 , 1 ) } 10% , 20% { transform: scale 3 d(. 9 , . 9 , . 9 ) rotate 3 d( 0 , 0 , 1 , -3 deg) } 30% , 50% , 70% , 90% { transform: scale 3 d( 1.1 , 1.1 , 1.1 ) rotate 3 d( 0 , 0 , 1 , 3 deg) } 40% , 60% , 80% { transform: scale 3 d( 1.1 , 1.1 , 1.1 ) rotate 3 d( 0 , 0 , 1 , -3 deg) } 100% { transform: scale 3 d( 1 , 1 , 1 ) } } |
補足
- クリックした時に設定するアニメーションのクラス( bounce, rubberBand, tada)を用意しておく。
- レイアウトが崩れる場合は リセットCSS・共通CSS の内容を確認。
jQuery
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | $( function (){ /* クリック時にアニメーション */ $( '[data-click-animation]' ).on( 'click' , function (){ var t = $( this ); var c = t.attr( 'data-click-animation' ); t.addClass(c); }); $( '[data-click-animation]' ).on( 'animationend' , function () { var t = $( this ); var c = t.attr( 'data-click-animation' ); t.removeClass(c); }); }); |
補足
- クリックした時に data-click-animation 属性に設定したアニメーションのクラスを追加し、アニメーションが終了したら追加されたクラスを削除する。
- デモページで使用している jQuery のバージョンは 1.12.4 。
HTML
1 2 3 4 5 | < ul > < li data-click-animation = "bounce" >< span class = "btn" >映画の一覧を表示</ span ></ li > < li data-click-animation = "rubberBand" >< span class = "btn" >音楽の一覧を表示</ span ></ li > < li data-click-animation = "tada" >< span class = "btn" >ドラマの一覧を表示</ span ></ li > </ ul > |
補足
- クリックされた時のアニメーションを data-click-animation 属性に指定する。