How can I set the cursor for a canvas when using EaselJS?
After a lot of debugging, I managed to figure out the problematic code: stage.enableMouseOver()
. I am using stage.enableMouseOver()
because I need to be able to mouse over various elements placed on the stage. However, I've found that subsequently trying to set the cursor for the canvas fails to do anything. stage.canvas.style.cursor = "text"
does nothing, as well as stage.cursor = "text"
. However, stage.canvas.style.cursor
works when stage.enableMouseOver()
is commented out.
This doesn't work:
var stage = new createjs.Stage("canvas");
stage.enableMouseOver(); // comment out this line to get it to work
$("button").click(function() {
stage.canvas.style.cursor = "text";
});
<script src="https://code.createjs.com/easeljs-0.8.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="change-cursor">
Use text cursor instead of default
</button>
<br>
<canvas id="canvas" width=100 height=100 style="background-color:whitesmoke"></canvas>
How can I get my chosen cursor to appear, without removing stage.enableMouseOver()
?
Example that does work, but comments out stage.enableMouseOver()
:
var stage = new createjs.Stage("canvas");
// stage.enableMouseOver();
$("button").click(function() {
stage.canvas.style.cursor = "text";
});
<script src="https://code.createjs.com/easeljs-0.8.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="change-cursor">
Use text cursor instead of default
</button>
<br>
<canvas id="canvas" width=100 height=100 style="background-color:whitesmoke"></canvas>
There is a cursor
property available in EaselJS, check the example below:
var stage = new createjs.Stage("canvas");
stage.cursor = 'text';
var bgShape = new createjs.Shape();
bgShape.graphics.beginFill("red").drawRect(0, 0, 100, 100);
stage.addChild(bgShape);
stage.enableMouseOver();
#canvas {
cursor: text;
}
<script src="https://code.createjs.com/easeljs-0.8.1.min.js"></script>
<canvas id="canvas" width=100 height=100 style="background-color:whitesmoke"></canvas>