我正在使用 KineticJS 在中间绘制一条垂直线和一条水平线以及一个圆圈。我已经对垂直线和圆圈进行了分组,但是我也想用水平线移动圆圈,这是我的脚本:
var stage1 = new Kinetic.Stage({
container: 'container',
width: 1024,
height: 1024
});
var blayer1 = new Kinetic.Layer();
var bgroup1 = new Kinetic.Group({
draggable: true,
dragBoundFunc: function (pos) {
return {
x: pos.x,
y: this.getAbsolutePosition().y
}
}
});
var BlueLine1 = new Kinetic.Line({
points: [512, 0, 512, 1024],
stroke: '#0080c0',
strokeWidth: 2,
lineCap: 'round',
lineJoin: 'round'
});
var circle = new Kinetic.Circle({
x: stage1.getWidth() / 2,
y: stage1.getHeight() / 2,
radius: 140,
stroke: '#00ffff',
strokeWidth: 2
});
bgroup1.add(circle);
bgroup1.add(BlueLine1);
blayer1.add(bgroup1);
stage1.add(blayer1);
blayer1.draw();
var glayer1 = new Kinetic.Layer();
var ggroup1 = new Kinetic.Group({
draggable: true,
dragBoundFunc: function (pos) {
return {
x: this.getAbsolutePosition().x,
y: pos.y
}
}
});
var GreenLine1 = new Kinetic.Line({
points: [0, 512, 1024, 512],
stroke: 'red',
strokeWidth: 2,
lineCap: 'round',
lineJoin: 'round'
});
ggroup1.add(GreenLine1);
glayer1.add(ggroup1);
stage1.add(glayer1);
glayer1.draw();
}