Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snap multiple relative points; 'startCoords' offset #133

Merged
merged 11 commits into from Dec 20, 2014
Merged

Conversation

taye
Copy link
Owner

@taye taye commented Dec 14, 2014

interact(target).draggable({
  snap: {
    targets: [ {x: 300, y: 300} ],
    relativePoints: [
      { x: 0, y: 0 },  // snap relative to the top left of the element
      { x: 1, y: 1 },  // and also to the bottom right
    ],  

    // offset the snap target coordinates
    // can be an object with x/y or 'startCoords'
    offset: { x: 50, y: 50 }
  }
});

relativePoints

The snap.relativePoints array succeeds the snap.elementOriign object. There are effectively ( targets.length * max( relativePoints.length, 1 ) ) snap targets when snap calculations are done. Snap functions are called multiple times with the coordinates of each relativePoint. If no relativePoints array is specified or the array is empty then snapping is relative to the pointer coordinates (default).

Backwards compatible – elementOrigin still works with the old snapping interface.

interact(target).snap({
  mode: 'anchor',
  anchors: [ {x: 300, y: 300} ],
  elementOrigin: { x: 0, y: 0 }    // only one elementOrigin is possible
});

offset

The x and y values of the snap offset are added to the target coordinates. If the offset is 'startCoords' then the pageX/Y of the down event that started the action are added to the target coordinates. See #135 for more info.

Closes #132
Closes #135

Effectively having multiple elementOrigins
@taye taye changed the title Snap multiple relative points Snap multiple relative points; 'startCoords' offset Dec 17, 2014
@taye taye merged commit f5a1335 into master Dec 20, 2014
@taye taye deleted the snap-relative-points branch December 31, 2014 19:58
@taye taye mentioned this pull request Mar 3, 2015
@taye taye mentioned this pull request Jul 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: snap relative to the mouse position Multiple snap points of one svg rect?
1 participant