Javascript 在Konva.js中,是否可以使用鼠标左键绘制并使用鼠标右键拖动舞台?
我正在尝试做一个应用程序,你可以在其中绘制自定义矩形形状的对象,并能够在同一时间拖动你的舞台。使用Konva.js是否可能Javascript 在Konva.js中,是否可以使用鼠标左键绘制并使用鼠标右键拖动舞台?,javascript,konvajs,Javascript,Konvajs,我正在尝试做一个应用程序,你可以在其中绘制自定义矩形形状的对象,并能够在同一时间拖动你的舞台。使用Konva.js是否可能 var stage = new Konva.Stage({ container: 'container', width: width, height: height }); document.addEventListener('mousedown', (e) => { switch (e.button) {
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height
});
document.addEventListener('mousedown', (e) => {
switch (e.button) {
case 0:
stage.draggable(false);
break;
case 2:
stage.draggable(true);
break;
}
});
好的,如果你想知道怎么做,这是一个可能的解决方案:
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height
});
document.addEventListener('mousedown', (e) => {
if(e.button === 0) stage.draggable(false);
});
document.addEventListener('mouseup', (e) => {
if(e.button === 0) stage.draggable(true);
});
要实现您的目标,您可以使用以下方法:
const stage=新Konva.stage({
容器:'容器',
宽度:window.innerWidth,
高度:window.innerHeight,
德拉格布尔:是的
});
const layer=新的Konva.layer();
阶段。添加(层);
恒圆=新康瓦圆({
x:stage.width()/2,
y:舞台高度()/2,
半径:50,
填充:“绿色”
});
图层。添加(圆圈);
layer.draw();
stage.on('contextmenu',e=>{
e、 evt.preventDefault();
})
舞台上('mousedown',(e)=>{
const isLeft=e.evt.button==0;
阶段。可拖动(!isLeft);
});代码>
您做过任何研究吗?请与我们分享你的研究成果