I try to play a specific animation every time I click a button.
In particular, I use the jQuery library and animate.css for this effect: when I click the button, a class is added (two classes, to be precise: fadeInDown animated ), to the element that I want to animate.
Animation works correctly, but only once. Why is this?
Fiddle: http://jsfiddle.net/jqm4vjLj/2/
I want the animation to be reset every time I click the button, even if it is halfway to completion from the previous click. It should also work when I press a button, not just once.
JS:
$("#button").click(function () { $("#button").removeClass(); $("#button").addClass("fadeInDown animated"); });
Classes from animate.css:
@-webkit-keyframes fadeInDown { 0% { opacity: 0; -webkit-transform: translateY(-20px); transform: translateY(-20px); } 100% { opacity: 1; -webkit-transform: translateY(0); transform: translateY(0); } } @keyframes fadeInDown { 0% { opacity: 0; -webkit-transform: translateY(-20px); -ms-transform: translateY(-20px); transform: translateY(-20px); } 100% { opacity: 1; -webkit-transform: translateY(0); -ms-transform: translateY(0); transform: translateY(0); } } .fadeInDown { -webkit-animation-name: fadeInDown; animation-name: fadeInDown; } .animated { -webkit-animation-duration: 1s; animation-duration: 1s; -webkit-animation-fill-mode: both; animation-fill-mode: both; }
Tiago source share