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

前端 未结 15 2043
自闭症患者
自闭症患者 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:56

    I got inspired from Korayem solution.

    Javascript:

    jQuery.ajaxSetup({
        beforeSend: function() {
           $('body').addClass('busy');
        },
        complete: function() {
           $('body').removeClass('busy');
        }
    });
    

    CSS:

    .busy * {
        cursor: wait !important;
    }
    

    Tested on Chrome, Firefox and IE 10. Cursor changes without moving the mouse. "!important" is needed for IE10.

    Edit: You still have to move cursor on IE 10 after the AJAX request is complete (so the normal cursor appear). Wait cursor appears without moving the mouse..

提交回复
热议问题