Wait cursor over entire html page

后端 未结 14 1347
离开以前
离开以前 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条回答
  •  猫巷女王i
    2020-12-02 14:38

    I have been struggling with this problem for hours today. Basically everything was working just fine in FireFox but (of course) not in IE. In IE the wait cursor was showing AFTER the time consuming function was executed.

    I finally found the trick on this site: http://www.codingforums.com/archive/index.php/t-37185.html

    Code:

    //...
    document.body.style.cursor = 'wait';
    setTimeout(this.SomeLongFunction, 1);
    
    //setTimeout syntax when calling a function with parameters
    //setTimeout(function() {MyClass.SomeLongFunction(someParam);}, 1);
    
    //no () after function name this is a function ref not a function call
    setTimeout(this.SetDefaultCursor, 1);
    ...
    
    function SetDefaultCursor() {document.body.style.cursor = 'default';}
    
    function SomeLongFunction(someParam) {...}
    

    My code runs in a JavaScript class hence the this and MyClass (MyClass is a singleton).

    I had the same problems when trying to display a div as described on this page. In IE it was showing after the function had been executed. So I guess this trick would solve that problem too.

    Thanks a zillion time to glenngv the author of the post. You really made my day!!!

提交回复
热议问题