From 6778e4422dc8a0a150a37d8de8e0fddf651f89c4 Mon Sep 17 00:00:00 2001 From: Taye Adeyemi Date: Fri, 1 Jun 2018 21:03:12 +0200 Subject: [PATCH] modifiers: add short README --- packages/modifiers/README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 packages/modifiers/README.md diff --git a/packages/modifiers/README.md b/packages/modifiers/README.md new file mode 100644 index 000000000..ad187f990 --- /dev/null +++ b/packages/modifiers/README.md @@ -0,0 +1,25 @@ +# modifiers + +Use modifiers to change the coordinates of drag, resize and gesture events. + +The `options` object passed to the action methods can have a `modifiers` array +which will be applied to events of that action type. + +```js +// create a restrict modifier to prevent dragging an element out of its parent +const restrictToParent = interact.modifiers.restrict({ + restriction: 'parent', + elementRect: { left: 0, right: 0, top: 1, bottom: 1 }, +}) + +// create a snap modifier which changes the event coordinates to the closest +// corner of a grid +const snap100x100 = interact.modifiers.snap({ + targets: [interact.snappers.grid({ x: 100, y: 100 })], +}), + +// apply the restrict and then the snap modifiers to drag events +interact(target).draggable({ + modifiers: [restrictToParent, snap100x100], +}) +```