Sometimes, we want to change cursor when loading page in JavaScript
In this article, we’ll look at how to change cursor when loading page in JavaScript.
How to change cursor when loading page in JavaScript?
To change cursor when loading page in JavaScript, we can set the cursor
CSS property of the body element.
For instance, we write:
document.body.style.cursor = 'wait';
setTimeout(() => {
document.body.style.cursor = 'default';
}, 2000)
We set document.body.style.cursor
to 'wait'
to show the loading cursor.
Then we set document.body.style.cursor
to 'default'
to show the default arrow cursor after 2 seconds.
Conclusion
To change cursor when loading page in JavaScript, we can set the cursor
CSS property of the body element.