konvajs / konva

Konva.js is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.
http://konvajs.org/
Other
11.59k stars 926 forks source link

dragBoundFunc only works on creation. Can't be set afterwards #193

Closed azev closed 7 years ago

azev commented 7 years ago

Works:

var layer = new Konva.Layer({
  draggable: true,
  dragBoundFunc : function(pos) {
    return {
        x: this.getAbsolutePosition().x,
        y: pos.y
}
}});

Doesn't work:

var layer = new Konva.Layer({
  draggable: true
});

layer.dragBoundFunc = function(pos) {
    return {
        x: this.getAbsolutePosition().x,
        y: pos.y
}
}

How can I set dragBoundFunc after the object creation?

lavrton commented 7 years ago

@azev dragBoundFunc in not a property. It is a method of an instance. Take a look at API docs: http://konvajs.github.io/api/Konva.Node.html#dragBoundFunc

node.dragBoundFunc(function(pos){
  return {
    x: this.getAbsolutePosition().x,
    y: pos.y
  };
});
azev commented 7 years ago

Thanks! attention failed :)