참고 : KineticJS는 캔버스 라이브러리입니다. 먼저 캔버스를 사용하려면 캔버스를 만들어야합니다.
<html>
<head></head>
<body>
<!--Some page content here -->
<!--Here you want to draw your line -->
<!--Make a container for the canvas, which kinetic will draw the line on -->
<div id="myCanvasContainer">
<!--Inside here your canvas will be created -->
</div>
</body>
</html>
그런 다음 JS 코드. 먼저 kinetic library을 가져옵니다.
//The stage creates the <canvas> element, it's like desktop
var stage = new Kinetic.Stage({
container: "myCanvasContainer",
height: 500,
width: 600
})
//A layer is like a paper, you can draw things on it, and then hide or query it
var layer = new Kinetic.Layer()
//Let's make our line
var line = new Kinetic.Line({
points: [5, 30, 300, 250], //[point1(x), point1(y), point2(x), point2(y)]
stroke: "lightcoral",
strokeWidth: 10
}).on("click", function(e){ //Here you subscribe to the click event
//Gets an array of the points [(Point){x=5, y=30}, (Point){x=300, y=250}]
alert(this.attrs["points"])
})
//Draw to paper
layer.add(line)
//Make paper visible on desktop
stage.add(layer)
희망 사항은 KineticJS입니다. 매우 흥미로운 도서관입니다.
Fiddle