JavaScript Cursor Change (and change back again)

前端 未结 7 1939
日久生厌
日久生厌 2021-01-17 11:14

I have this page that does some funky database stuff that takes a couple seconds to process, and in the meantime I\'d like to set a \"wait\" cursor so the user

7条回答
  •  终归单人心
    2021-01-17 11:39

    What I suggest is two things: a) Better write a CSS like

    body.waiting * { cursor: wait; }
    

    b) Use the JS to handle the body class

    /* when you need to wait */
    document.body.className = 'waiting';
    /* to remove the wait state */
    document.body.className = ''; // could be empty or whatever you want
    

    You might want to add the class instead of replace the whole class attribute, what I suggest is to use something like jQuery for that.

    EDIT 2019: don't use jQuery for just this, use classList

提交回复
热议问题