How can I create a “Please Wait, Loading…” animation using jQuery?

后端 未结 17 1990
长情又很酷
长情又很酷 2020-11-22 00:07

I would like to place a \"please wait, loading\" spinning circle animation on my site. How should I accomplish this using jQuery?

17条回答
  •  逝去的感伤
    2020-11-22 00:44

    With all due respect to other posts, you have here a very simple solution, using CSS3 and jQuery, without using any further external resources nor files.

    $('#submit').click(function(){
      $(this).addClass('button_loader').attr("value","");
      window.setTimeout(function(){
        $('#submit').removeClass('button_loader').attr("value","\u2713");
        $('#submit').prop('disabled', true);
      }, 3000);
    });
    #submit:focus{
      outline:none;
      outline-offset: none;
    }
    
    .button {
        display: inline-block;
        padding: 6px 12px;
        margin: 20px 8px;
        font-size: 14px;
        font-weight: 400;
        line-height: 1.42857143;
        text-align: center;
        white-space: nowrap;
        vertical-align: middle;
        -ms-touch-action: manipulation;
        cursor: pointer;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        background-image: none;
        border: 2px solid transparent;
        border-radius: 5px;
        color: #000;
        background-color: #b2b2b2;
        border-color: #969696;
    }
    
    .button_loader {
      background-color: transparent;
      border: 4px solid #f3f3f3;
      border-radius: 50%;
      border-top: 4px solid #969696;
      border-bottom: 4px solid #969696;
      width: 35px;
      height: 35px;
      -webkit-animation: spin 0.8s linear infinite;
      animation: spin 0.8s linear infinite;
    }
    
    @-webkit-keyframes spin {
      0% { -webkit-transform: rotate(0deg); }
      99% { -webkit-transform: rotate(360deg); }
    }
    
    @keyframes spin {
      0% { transform: rotate(0deg); }
      99% { transform: rotate(360deg); }
    }
    
    

提交回复
热议问题