Programming Tips - Konva: constrain where a user can drag a shape

Date: 2024mar7 Library: Konva Language: javaScript Q. Konva: constrain where a user can drag a shape A. Use dragBoundFunc like this:
let text = new Konva.Text({ ... draggable: true, dragBoundFunc: function(pos) { if (x is out of bounds) { pos.x = this.absolutePosition().x, } if (y is out of bounds) { pos.y = this.absolutePosition().y, } return pos; } });
This is better than doing something after the fact in on('dragmove') More info http://www.google.com/search?q=Konva+dragBoundFunc