I'm currently refactoring the LocCom login system. This includes checking user login via AJAX and displaying an unsuccessful authorization by a shake animation on the login form. This works on IE 10+, FF 14+, Chrome 21+, Safari 5.1+ and Opera 12+.
At first the animation needs keyframes in CSS:
@keyframes shake{
0% { transform: translate(15px, 0); }
50% { transform: translate(-15px, 0); }
100% { transform: translate(0, 0); }
}
@-o-keyframes shake{
0% { -o-transform: translate(15px, 0); }
50% { -o-transform: translate(-15px, 0); }
100% { -o-transform: translate(0, 0); }
}
@-moz-keyframes shake{
0% { -moz-transform: translate(15px, 0); }
50% { -moz-transform: translate(-15px, 0); }
100% { -moz-transform: translate(0, 0); }
}
@-webkit-keyframes shake {
0% { -webkit-transform: translate(15px, 0); }
50% { -webkit-transform: translate(-15px, 0); }
100% { -webkit-transform: translate(0, 0); }
}
Then I define a css class witch I can add to an element via JS/jQuery to trigger the shake:
.shake {
animation-name: shake;
animation-duration: 200ms;
animation-iteration-count: 2;
-o-animation-name: shake;
-o-animation-duration: 200ms;
-o-animation-iteration-count: 2;
-moz-animation-name: shake;
-moz-animation-duration: 200ms;
-moz-animation-iteration-count: 2;
-webkit-animation-name: shake;
-webkit-animation-duration: 200ms;
-webkit-animation-iteration-count: 2;
}
Then to trigger the animation in jQuery:
$("#elem").on('click', function () {
if (!$(this).hasClass("shake")) {
$(this).addClass("shake");
} else {
var that=this;
$(this).removeClass("shake");
setTimeout(function () {
$(that).addClass("shake")
}, 0);
}
});
You need the timeout for the event to trigger multiple times. I will give ab update when you can see this feature live. It won't take long!
Update: This feature is now live on www.loc-com.de! Just try logging in without correct credentials!