mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 18:10:54 +08:00
Fix dbltap
event in Safari. close #1209
This commit is contained in:
@@ -34,31 +34,6 @@
|
||||
const layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
|
||||
const cellWidth = stage.width() / 10;
|
||||
const cellHeight = stage.width() / 10;
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
layer.add(
|
||||
new Konva.Line({
|
||||
x: i * cellWidth,
|
||||
points: [0, 0, 0, stage.height()],
|
||||
stroke: 'black',
|
||||
strokeWidth: 1,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
layer.add(
|
||||
new Konva.Line({
|
||||
y: i * cellHeight,
|
||||
points: [0, 0, stage.width(), 0],
|
||||
stroke: 'black',
|
||||
strokeWidth: 1,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const rect = new Konva.Rect({
|
||||
x: 90,
|
||||
y: 90,
|
||||
@@ -69,42 +44,9 @@
|
||||
});
|
||||
layer.add(rect);
|
||||
|
||||
const tr = new Konva.Transformer({
|
||||
nodes: [rect],
|
||||
anchorDragBoundFunc: function (oldPos, pos, event) {
|
||||
const closestX = Math.round(pos.x / cellWidth) * cellWidth;
|
||||
const diffX = Math.abs(pos.x - closestX);
|
||||
|
||||
const closestY = Math.round(pos.y / cellHeight) * cellHeight;
|
||||
const diffY = Math.abs(pos.y - closestY);
|
||||
|
||||
const snappedX = diffX < 10;
|
||||
const snappedY = diffY < 10;
|
||||
|
||||
if (snappedX && !snappedY) {
|
||||
return {
|
||||
x: closestX,
|
||||
y: oldPos.y,
|
||||
};
|
||||
} else if (snappedY && !snappedX) {
|
||||
return {
|
||||
x: oldPos.x,
|
||||
y: closestY,
|
||||
};
|
||||
} else if (snappedX && snappedY) {
|
||||
return {
|
||||
x: closestX,
|
||||
y: closestY,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
x: pos.x,
|
||||
y: pos.y,
|
||||
};
|
||||
}
|
||||
},
|
||||
rect.on('dbltap tap', (e) => {
|
||||
console.log(e.type);
|
||||
});
|
||||
layer.add(tr);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user