Categories
JavaScript Answers

How to change cursor when loading page in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *