Loading animation using Jquery

This code is to add a loading animation to the ‘Log in’ button on a website. using Jquery

 HTML:
<button type="submit" class="login-register-login-submit" data-action="login-button id ="login_btn">
{{translate 'Log In'}}
</button>
<div id="overlay">
       <div class="cv-spinner">
         <span class="spinner"></span>
        </div>
    </div>

jQuery:
            jQuery(function($){
              $(document).ajaxSend(function() {
                $("#overlay").fadeIn(300); 
              });
              $('#login_btn').click(function(){
                $.ajax({
                  type: 'GET',
                  success: function(data){
                    console.log(data);
                  }
                }).done(function() {
                  setTimeout(function(){
                    $("#overlay").fadeOut(300);
                  },1000);
                });
              });
            });
CSS:
#overlay{
	position: fixed;
	top: 0;
	left:0;
	z-index: 100;
	width: 100%;
	height:100%;
	display: none;
	background: rgba(0,0,0,0.6);
}
.cv-spinner {
	height: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
}
.spinner {
	width: 40px;
	height: 40px;
	border: 4px #ddd solid;
	border-top: 4px #2e93e6 solid;
	border-radius: 50%;
	animation: sp-anime 0.8s infinite linear;
}
@keyframes sp-anime {
	100% {
		transform: rotate(360deg);
	}
}
.is-hide{
	display:none;
}

Leave a comment

Your email address will not be published. Required fields are marked *