Getting the browser cursor from “wait” to “auto” without the user moving the mouse

前端 未结 15 2028
自闭症患者
自闭症患者 2020-11-27 13:49

I use this jQuery code to set the mouse pointer to its busy state (hourglass) during an Ajax call...

$(\'body\').css(\'cursor\', \'wait\');

15条回答
  •  星月不相逢
    2020-11-27 13:54

    Korayem's solution works for me in 100% cases in modern Chrome, Safari, in 95% cases in Firefox, but does not work in Opera and IE.

    I improved it a bit:

    $('html').bind('ajaxStart', function() {
        $(this).removeClass('notbusy').addClass('busy');
    }).bind('ajaxStop', function() {
        $(this).removeClass('busy').addClass('notbusy');
    });
    

    CSS:

    html.busy, html.busy * {
        cursor: wait !important;
    }
    
    html.notbusy, html.notbusy * {
        cursor: default !important;
    }
    

    Now it works in 100% cases in Chrome, Safari, Firefox and Opera. I do not know what to do with IE :(

提交回复
热议问题