Wait cursor over entire html page

后端 未结 14 1346
离开以前
离开以前 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:36

    I used a adaptation of Eric Wendelin's solution. It will show a transparent, animated overlay wait-div over the whole body, the click will be blocked by the wait-div while visible:

    css:

    div#waitMask {
        z-index: 999;
        position: absolute;
        top: 0;
        right: 0;
        height: 100%;
        width: 100%;
        cursor: wait;
        background-color: #000;
        opacity: 0;
        transition-duration: 0.5s;
        -webkit-transition-duration: 0.5s;
    }
    

    js:

    // to show it
    $("#waitMask").show();
    $("#waitMask").css("opacity"); // must read it first
    $("#waitMask").css("opacity", "0.8");
    
    ...
    
    // to hide it
    $("#waitMask").css("opacity", "0");
    setTimeout(function() {
        $("#waitMask").hide();
    }, 500) // wait for animation to end
    

    html:

    
        
        ... rest of html ...
    

提交回复
热议问题