Make validation on the login page with a shake effect. If you have a WordPress site, it’s no stranger to a “shake effect” when you fail to log in to the dashboard page. Of course, it’s interesting if we implement the shake effect login form on the application that we are developing. Check out the quick tips for creating a login form vibrate effect.
In this tutorial, I will show you how to create a login form with a shake animation effect using CSS3 and JQuery. If the user incorrectly entered a username and password combination on the login form provided, it will display a shake form with animation
Table of Contents
Make animated Shake effects on CSS
Using CSS3 allows creating animations on HTML elements without using JavaScript or Flash.
What are the CSS3 animations?
Animation allows elements to move from one style to another. You can change the CSS properties to your liking.
The main component of CSS animation is @keyframes, CSS rules where animation is defined. @keyframes are the steps that compile the timeline in the animation. In @keyframes, you can specify the stages with different styles.
CSS Shake Effect
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | .shake { animation: shake 0.3s; animation-iteration-count: infinite; } @keyframes shake { 0% { transform: translate(1px, 1px) rotate(0deg); } 20% { transform: translate(-3px, 0px) rotate(1deg); } 40% { transform: translate(1px, -1px) rotate(1deg); } 60% { transform: translate(-3px, 1px) rotate(0deg); } 80% { transform: translate(-1px, -1px) rotate(1deg); } 100% { transform: translate(1px, -2px) rotate(-1deg); } } form { margin: 0 auto; border: 1px solid grey; padding:10px; width: 300px; } #errortext{ color:red; } |
Creating a Login Page
Create a login page that we will validate the shake effect
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <div class="container"> <form action="action_page.php"> <h3>Login Form</h3> <table> <tr> <td colspan="2" id="errortext"></td> </tr> <tr> <td><b>Username</b></td> <td><input type="text" placeholder="Enter Username" id="txtuname"></td> </tr> <tr> <td><b>Password</b></td> <td><input type="password" placeholder="Enter Password" id="txtpsw"></td> </tr> <tr> <td> </td> <td><button id="btn-login" type="submit">Login</button></td> </tr> </table> </form> </div> |
Make Validation with jQuery
we use JQuery to validate and add shake CSS class to the element form.
Copy the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | $(document).ready(function(){ $("#btn-login").click(function(e){ e.preventDefault(); var uname = $("#txtuname").val(); var pass = $("#txtpsw").val(); if(uname !== 'test' && pass !== 'test'){ $("#errortext").html("* Username / Password incorect") $("form").addClass("shake"); setTimeout(function(){$("form").removeClass("shake"); }, 500); $("#txtuname").focus(); }else{ $("#errortext").html("") alert("Success login !"); } }); }) |
If successful, display login form shake effect validation as shown below
Demo of Login Form Shake Effect Validation
Demo : How to Make a Shake Effect Validation Like the WordPress Login Form
Other Article : How To Create Auto Increment Using CSS Counter
Conclusion
Making a shake effect/vibrate form validation is quite easy. Using CSS effects makes the application page more attractive and interactive.
So a short tutorial on how to make vibrate/shake effect for form validation that resembles a login page on WordPress
Leave a Reply