如果我创建了一个图像层,那么如何在图像层上隐藏和显示一个文本层。到目前为止,我已经创建了图像层。并让它为我提供文本层,但它随后删除了图像层。我也无法通过鼠标单击使其在舞台上工作。
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<div id="container"></div>
<div id="nupud">
<button id="show">
show
</button>
<button id="hide">
hide
</button>
</div>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.5.4.min.js"></script>
<script defer="defer">
var stage = new Kinetic.Stage({
container: 'container',
width: 1600,
height: 800
});
var layer = new Kinetic.Layer();
var tekst = new Kinetic.Text({
x:stage.getWidth() / 2,
y: 15,
text: 'Simple Tekst',
fontSize: 30,
fontFamily: 'Calibri',
fill: 'green'
});
var imageObj = new Image();
imageObj.onload = function() {
var taust = new Kinetic.Image({
x: 0,
y: 0,
image: imageObj,
width: 1600,
height: 800
});
// add the shape to the layer
layer.add(taust);
};
//add the text layer
layer.add(tekst);
// add button event bindings
document.getElementById('show').addEventListener('click', function() {
tekst.show();
layer.draw();
}, false);
document.getElementById('hide').addEventListener('click', function() {
tekst.hide();
layer.draw();
}, false);
imageObj.src = 'Untitled.png';
//taust lõppeb
</script>
</body>
</html>