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

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

    Along with what Jonathan and Samir suggested (both excellent answers btw!), jQuery has some built in events that it'll fire for you when making an ajax request.

    There's the ajaxStart event

    Show a loading message whenever an AJAX request starts (and none is already active).

    ...and it's brother, the ajaxStop event

    Attach a function to be executed whenever all AJAX requests have ended. This is an Ajax Event.

    Together, they make a fine way to show a progress message when any ajax activity is happening anywhere on the page.

    HTML:

    Please Wait

    Script:

    $(document).ajaxStart(function(){
        $('#loading').show();
     }).ajaxStop(function(){
        $('#loading').hide();
     });
    

提交回复
热议问题