Changing cursor to waiting in javascript/jquery

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

    Setting the cursor for 'body' will change the cursor for the background of the page but not for controls on it. For example, buttons will still have the regular cursor when hovering over them. The following is what I am using:

    To set the 'wait' cursor, create a style element and insert in the head:

    var css = "* { cursor: wait; !important}";
    var style = document.createElement("style");
    style.type = "text/css";
    style.id = "mywaitcursorstyle";
    style.appendChild(document.createTextNode(css));
    document.head.appendChild(style);
    

    Then to restore the cursor, delete the style element:

    var style = document.getElementById("mywaitcursorstyle");
    if (style) {
      style.parentNode.removeChild(style);
    }
    

提交回复
热议问题