Changing cursor to waiting in javascript/jquery

后端 未结 13 2036
孤街浪徒
孤街浪徒 2020-12-04 10:43

\"enter

How would i get my cursor to change to this loading icon when a function is ca

相关标签:
13条回答
  • 2020-12-04 11:00

    If it saves too fast, try this:

    <style media="screen" type="text/css">
        .autosave {display: inline; padding: 0 10px; color:green; font-weight: 400; font-style: italic;}
    </style>
    
    <input type="button" value="Save" onclick="save();" />&nbsp;
    <span class="autosave" style="display: none;">Saved Successfully</span>
    
    
    $('span.autosave').fadeIn("80");
    $('span.autosave').delay("400");
    $('span.autosave').fadeOut("80");
    
    0 讨论(0)
  • 2020-12-04 11:05

    The following is my preferred way, and will change the cursor everytime a page is about to change i.e. beforeunload

    $(window).on('beforeunload', function(){
       $('*').css("cursor", "progress");
    });
    
    0 讨论(0)
  • 2020-12-04 11:05
    $('#some_id').click(function() {
      $("body").css("cursor", "progress");
      $.ajax({
        url: "test.html",
        context: document.body,
        success: function() {
          $("body").css("cursor", "default");
        }
      });
    });
    

    This will create a loading cursor till your ajax call succeeds.

    0 讨论(0)
  • 2020-12-04 11:06

    In your jQuery use:

    $("body").css("cursor", "progress");
    

    and then back to normal again

    $("body").css("cursor", "default");
    
    0 讨论(0)
  • 2020-12-04 11:07

    jQuery:
    $("body").css("cursor", "progress");

    back again
    $("body").css("cursor", "default");

    Pure:
    document.body.style.cursor = 'progress';

    back again
    document.body.style.cursor = 'default';

    0 讨论(0)
  • 2020-12-04 11:11

    Please don't use jQuery for this in 2018! There is no reason to include an entire external library just to perform this one action which can be achieved with one line:

    Change cursor to spinner: document.body.style.cursor = 'wait';

    Revert cursor to normal: document.body.style.cursor = 'default';

    0 讨论(0)
提交回复
热议问题