这是我目前的状态:http: //jsfiddle.net/andrewgable/Xr6mc/
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="http://www.html5canvastutorials.com/libraries/kinetic-v4.3.0-beta2.js"></script>
<script>
var stage = new Kinetic.Stage({
container: 'container',
width: 578,
height: 200
});
var lineLayer = new Kinetic.Layer();
var flowerLayer = new Kinetic.Layer();
var centerLayer = new Kinetic.Layer();
var flower = new Kinetic.Group({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2
});
// build stem
var stem = new Kinetic.Line({
strokeWidth: 10,
stroke: 'green',
points: [{
x: flower.getX(),
y: flower.getY()
}, {
x: stage.getWidth() / 2,
y: stage.getHeight() + 10
}]
});
// build center
var center = new Kinetic.Circle({
x: 0,
y: 0,
radius: 6,
fill: 'black',
draggable: true,
x: stage.getWidth() / 2,
y: stage.getHeight() / 2
});
center.on('mouseover', function() {
this.setFill('orange');
flowerLayer.draw();
document.body.style.cursor = 'pointer';
});
center.on('mouseout', function() {
this.setFill('black');
flowerLayer.draw();
document.body.style.cursor = 'default';
});
stage.on('mouseup', function() {
document.body.style.cursor = 'default';
});
lineLayer.add(stem);
flowerLayer.add(flower);
centerLayer.add(center);
stage.add(lineLayer);
stage.add(flowerLayer);
stage.add(centerLayer);
// keep step and flower position in sync with center
center.on('dragstart', (function() {
center.getLayer().afterDraw(function() {
stem.attrs.points[0] = center.getPosition();
flower.setPosition(center.getPosition());
lineLayer.draw();
flowerLayer.draw();
});
}));
</script>
</body>
</html>
只是试图使这条线可拖动(简单,将其设置为拖动)。
我希望这条线有两个锚点,都可以向任何方向拖动。
正如你所看到的,我只需要做一个“锚”点。
如果没有锚点移动,我无法弄清楚使这成为可能的逻辑..
谢谢你的帮助。