隐藏和显示与KineticJS形状,我们可以设置可见财产当我们实例化一个形状,或者我们可以使用hide() 和 show()方法。
说明:点击按钮来显示和隐藏的形状。
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
#buttons {
position: absolute;
left: 10px;
top: 0px;
}
button {
margin-top: 10px;
display: block;
}
</style>
</style>
</head>
<body>
<div id="container"></div>
<div id="buttons">
<button id="show">
show
</button>
<button id="hide">
hide
</button>
</div>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.1.min.js"></script>
<script defer="defer">
var stage = new Kinetic.Stage({
container: 'container',
width: 578,
height: 200
});
var layer = new Kinetic.Layer();
var pentagon = new Kinetic.RegularPolygon({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2,
sides: 5,
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
visible: false
});
// add the shape to the layer
layer.add(pentagon);
// add the layer to the stage
stage.add(layer);
// add button event bindings
document.getElementById('show').addEventListener('click', function() {
pentagon.show();
layer.draw();
}, false);
document.getElementById('hide').addEventListener('click', function() {
pentagon.hide();
layer.draw();
}, false);
</script>
</body>
</html>