taye / interact.js

JavaScript drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE9+)
http://interactjs.io/
MIT License
12.19k stars 782 forks source link

Set snap on or off by user #1033

Open Dutchstyler opened 3 months ago

Dutchstyler commented 3 months ago

Just work with the script for 2 weeks and love it. But is it possible to set the snap on and off? Tryed a few things but I 'm to new with this to understand.

Thouht to set a input value and read this out to edit the modifier. But that`s not working.

What I have by now:

var gridTarget = interact.snappers.grid({ // can be a pair of x and y, left and top, // right and bottom, or width, and height x: document.getElementById("gridsnap").value, y: 10

});

// target elements with the "draggable" class interact('.draggable') .draggable({ // enable inertial throwing inertia: false, modifiers: [ / interact.modifiers.snap({ targets: [ //interact.snappers.grid({ x: 3.5, y: 3.5 }) gridTarget ], range: Infinity, relativePoints: [ { x: 0, y: 0 } ] }),/ interact.modifiers.snap({ targets: [gridTarget] }), interact.modifiers.restrictRect({ //Blijf binnen het huidige element. restriction: 'parent', endOnly: false }) ],

// enable autoScroll
autoScroll: false,

listeners: {
  // call this function on every dragmove event
  move: dragMoveListener,

  // call this function on every dragend event
  end (event) {

  }
}

})