0
votes

I have a DOM element that I want to drop "items" into. I want to give the user visual feedback with changing the cursor icon. But while mouse button is held down the cursor doesn't change. If I move the mouse no button, it changes. But not when I hold the button. Why? How can I achieve the desired cursor feedback for the user? I'm using Google Chrome.

<html>
    <head>      
        <script type="text/javascript">         
            function Document()
            {
                var that = document.createElement("div");
                that.style.backgroundColor = "#80ff80";
                that.style.border = "1px solid black";
                that.style.height = "90%";
                that.style.width = "50%";
                that.onmousemove = function (event)
                {
                    //console.log(event.offsetX + ", " + event.offsetY);
                    if (Math.random() < 0.5)
                        that.style.cursor = "not-allowed";
                    else
                        that.style.cursor = "move";
                    return false;
                }
                return that;
            }

            function onLoadPage()
            {
                var doc = new Document();
                document.body.appendChild(doc);
            }

        </script>
    </head>
    <body onload="onLoadPage()" />
</html>

1) Move mouse over the div. It will randomly change cursor icons.
2) Press mouse button and move mouse over the div. It will keep the last icon until you release mouse button.

Edit:
Chrome's console might produce this issue. Cursor change seems to work well when I hide the "developer tools". When I enable "dev tools", change tabs to any tab and back, the cursor wont change with mouse button held down.

1
Are you appending the newly created element to the DOM? - Teemu
Yes, of course. The green style is to see where it is and try out. - Bitterblue
I can't reproduce the issue ..? - Teemu
OK. Firefox doesn't seem to have that issue. I was working with Chrome. - Bitterblue
@Teemu Thanks for your time. I guess the dev tools produce the issue, See edit. - Bitterblue

1 Answers

0
votes

I am not able to reproduce your issue but I came across the following link which also suggests a bug in all the browsers except firefox. It is an old link but may be helpful.

https://github.com/RubaXa/Sortable/issues/246