Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouse cursor set using jQuery/CSS not changing until mouse moved

In my code I use the jQuery/CSS to set and unset the 'wait' mouse cursor with the following code:

  function setWaitCursor() {
    $('body').css('cursor', 'wait');
  }

  function setDefaultCursor() {
    $('body').css('cursor', '');
  }

I use this code to change the mouse cursor for a long operation:

setWaitCursor();

... do stuff that takes a few seconds ...

setDefaultCursor();

This code doesn't seem to work unless you move the mouse, however (at least for Chrome on Win 10). If the mouse is not moved after setDefaultCursor is called, the cursor displays the 'wait' cursor until the mouse is moved (or vice versa).

Example: https://jsfiddle.net/antonyakushin/0jv6rqkf/

In this fiddle, the cursor changes for 2 seconds after the link is clicked. If you don't move the mouse when you click the link, the cursor does not change.

What is the best way to resolve this issue, so that even if the mouse is not moved the cursor is changed?

like image 317
Anton Avatar asked Apr 13 '16 11:04

Anton


People also ask

How do I change my mouse pointer to CSS?

You can simply use the CSS cursor property with the value pointer to change the cursor into a hand pointer while hover over any element and not just hyperlink. In the following example when you place the cursor over the list item, it will change into a hand pointer instead of the default text selection cursor.

Which property allows changing the style of the mouse cursor CSS?

The cursor CSS property specifies the mouse cursor displayed when the mouse pointer is over an element. In this tutorial, we're going to see the CSS cursor property which, as you'd expect, allows you to change the cursor style as the mouse hover over an element.


1 Answers

Although this is not the answer to this specific problem, this behavior can happen:

  • On Chrome
  • With DevTools open (which is very likely, in order to debug this issue)

The solution is simply to close the Chrome DevTools.

like image 176
philippe_b Avatar answered Sep 17 '22 11:09

philippe_b