Changing cursor to waiting in javascript/jquery

后端 未结 13 2041
孤街浪徒
孤街浪徒 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:12

    A colleague suggested an approach that I find preferable to the chosen solution here. First, in CSS, add this rule:

    body.waiting * {
        cursor: progress;
    }
    

    Then, to turn on the progress cursor, say:

    $('body').addClass('waiting');
    

    and to turn off the progress cursor, say:

    $('body').removeClass('waiting');
    

    The advantage of this approach is that when you turn off the progress cursor, whatever other cursors may have been defined in your CSS will be restored. If the CSS rule is not powerful enough in precedence to overrule other CSS rules, you can add an id to the body and to the rule, or use !important.

提交回复
热议问题