html5 canvas hand cursor problems

后端 未结 3 1032
萌比男神i
萌比男神i 2020-12-15 08:16

I\'m playing around with html5 and some javascript to make a minor sketchpad. Whenever I click down on the canvas in chrome, the cursor becomes a text cursor. I have tried p

3条回答
  •  Happy的楠姐
    2020-12-15 09:05

    While the other guys were absolutely bang on referring you to the quirksmode reference, that won't fix the problem you are having, and essentially you need to implement a variation of Kris's answer.

    In my own implementation, I found that preventing default behaviour in the mousedown event was all that was required to stop that pesky text selection cursor:

    function handleMouseDown(evt) {
      evt.preventDefault();
      evt.stopPropagation();
    
      // you can change the cursor if you want
      // just remember to handle the mouse up and put it back :)
      evt.target.style.cursor = 'move';
    
      // rest of code goes here
    }
    
    document.addEventListener('mousedown', handleMouseDown, false);
    

    Hope that helps.

    Cheers, Damon.

提交回复
热议问题