When I use that:
$("#passwordConfig").removeClass('shake animated').addClass('shake animate');
This works only ONCE.
I need to add some timeOut to make it run as many times as I want!
$("#passwordConfig").removeClass('shake animated');
setTimeout(function() {
$("#passwordConfig").addClass('shake animated');
}, 50);
Any idea why ?
CSS:
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
@-webkit-keyframes shake {
0%, 100% {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
10%, 30%, 50%, 70%, 90% {
-webkit-transform: translate3d(-10px, 0, 0);
transform: translate3d(-10px, 0, 0);
}
20%, 40%, 60%, 80% {
-webkit-transform: translate3d(10px, 0, 0);
transform: translate3d(10px, 0, 0);
}
}
@keyframes shake {
0%, 100% {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
10%, 30%, 50%, 70%, 90% {
-webkit-transform: translate3d(-10px, 0, 0);
transform: translate3d(-10px, 0, 0);
}
20%, 40%, 60%, 80% {
-webkit-transform: translate3d(10px, 0, 0);
transform: translate3d(10px, 0, 0);
}
}
.shake {
-webkit-animation-name: shake;
animation-name: shake;
}
This is because removeClass and addClass happening so quickly it doesn't allow the DOM to catch up per say. You can do something like this if you really hate setTimeout:
$("#passwordConfig").removeClass('shake animated').delay(50).queue(
function (next) {
$(this).addClass('shake animated');
next();
}
);
http://jsfiddle.net/51dwhd2o/
Toggle class is fine too but seems like it would only work every other call of toggle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With