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

后端 未结 17 1979
长情又很酷
长情又很酷 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:54

    If you are using Turbolinks With Rails this is my solution:

    This is the CoffeeScript

    $(window).on 'page:fetch', ->
      $('body').append("")
      $('body').addClass("loading")
    
    $(window).on 'page:change', ->
      $('body').removeClass("loading")
    

    This is the SASS CSS based on the first excellent answer from Jonathan Sampson

    # loader.css.scss
    
    .modal {
        display:    none;
        position:   fixed;
        z-index:    1000;
        top:        0;
        left:       0;
        height:     100%;
        width:      100%;
        background: rgba( 255, 255, 255, 0.4)
                asset-url('ajax-loader.gif', image)
                50% 50% 
                no-repeat;
    }
    body.loading {
        overflow: hidden;   
    }
    
    body.loading .modal {
        display: block;
    }
    

提交回复
热议问题