Wait cursor over entire html page

后端 未结 14 1334
离开以前
离开以前 2020-12-02 14:19

Is it possible to set the cursor to \'wait\' on the entire html page in a simple way? The idea is to show the user that something is going on while an ajax call is being com

14条回答
  •  情歌与酒
    2020-12-02 14:38

    My Two pence:

    Step 1: Declare an array. This will be used to store the original cursors that were assigned:

    var vArrOriginalCursors = new Array(2);
    

    Step 2: Implement the function cursorModifyEntirePage

     function CursorModifyEntirePage(CursorType){
        var elements = document.body.getElementsByTagName('*');
        alert("These are the elements found:" + elements.length);
        let lclCntr = 0;
        vArrOriginalCursors.length = elements.length; 
        for(lclCntr = 0; lclCntr < elements.length; lclCntr++){
            vArrOriginalCursors[lclCntr] = elements[lclCntr].style.cursor;
            elements[lclCntr].style.cursor = CursorType;
        }
    }
    

    What it does: Gets all the elements on the page. Stores the original cursors assigned to them in the array declared in step 1. Modifies the cursors to the desired cursor as passed by parameter CursorType

    Step 3: Restore the cursors on the page

     function CursorRestoreEntirePage(){
        let lclCntr = 0;
        var elements = document.body.getElementsByTagName('*');
        for(lclCntr = 0; lclCntr < elements.length; lclCntr++){
            elements[lclCntr].style.cursor = vArrOriginalCursors[lclCntr];
        }
    }
    

    I have run this in an application and it works fine. Only caveat is that I have not tested it when you are dynamically adding the elements.

提交回复
热议问题