I'm beginning to use canvas and kineticjs. I tried to draw a rect when clicking the button "add text", in the function I declare a var Text
, add the var Text
in the layer and then add the layer to the stage, can anybody help me?
window.onload = function() {
var stage = new Kinetic.Stage({
container: "container",
width: 578,
height: 200
});
var shapesLayer = new Kinetic.Layer();
document.getElementById("Draw_text").addEventListener("click", function () {
var Text = new Kinetic.Text({
x: 100,
y: 100,
text: "hi",
draggable: "true"
});
shapesLayer.add(Text);
stage.add(shapesLayer);
}, false);
<body onmousedown="return false;">
<div id="container"></div>
<div id="buttons">
<button id="Draw_text">
add text
</button>
</div>