wout/svg.draggable.js — pull request #17 by FlorianLoch (2014-02-21 16:13:29+00:00)
Title: Added possibily to restrict dragging by a callback function not only by constrain-object

Hey,
I needed this feature and therefore implemented it. I think it would be useful for others too, therefore I request you to merge this into the main repository.

Btw: SVG.js is really a great piece of coding!

Best regards,
Florian Loch

---

Instead of calling draggable() with an object you might also call it with a function. This function can return a boolean or a object of the form {x, y}, to which the element will be moved. "False" skips moving, true moves to raw x, y.

The following example will prevent the rectangle from "crossing the imaginary border" at x = 300:

```javascript
rect.draggable(function (x, y) {
var res = {x: x, y: y};

if (x > 300) {
res.x = 300;
}

return res;
});
```