Wait cursor over entire html page

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

    Easiest way I know is using JQuery like this:

    $('*').css('cursor','wait');
    
    0 讨论(0)
  • 2020-12-02 14:53

    Here is a more elaborate solution that does not require external CSS:

    function changeCursor(elem, cursor, decendents) {
        if (!elem) elem=$('body');
    
        // remove all classes starting with changeCursor-
        elem.removeClass (function (index, css) {
            return (css.match (/(^|\s)changeCursor-\S+/g) || []).join(' ');
        });
    
        if (!cursor) return;
    
        if (typeof decendents==='undefined' || decendents===null) decendents=true;
    
        let cname;
    
        if (decendents) {
            cname='changeCursor-Dec-'+cursor;
            if ($('style:contains("'+cname+'")').length < 1) $('<style>').text('.'+cname+' , .'+cname+' * { cursor: '+cursor+' !important; }').appendTo('head');
        } else {
            cname='changeCursor-'+cursor;
            if ($('style:contains("'+cname+'")').length < 1) $('<style>').text('.'+cname+' { cursor: '+cursor+' !important; }').appendTo('head');
        }
    
        elem.addClass(cname);
    }
    

    with this you can do:

    changeCursor(, 'wait'); // wait cursor on all decendents of body
    changeCursor($('#id'), 'wait', false); // wait cursor on elem with id only
    changeCursor(); // remove changed cursor from body
    
    0 讨论(0)
提交回复
热议问题