Dragging by using a handle. #66

Closed
matula opened this Issue Aug 14, 2014 · 6 comments

Projects

None yet

5 participants

@matula
matula commented Aug 14, 2014

This is a great library, thanks for the work and releasing it!
I was wondering if there was a way to make an element draggable, but only by clicking a handle in the element? That way, the whole element isn't clickable. Thanks!

@taye
Owner
taye commented Aug 15, 2014

There's no setting for this so you would have to change the target yourself in your event listeners.

I could implement something like an allowFrom options which would be sort of the reverse of ignoreFrom to only start actions from the matching element or it's children.

@taye
Owner
taye commented Aug 31, 2014

I've implemented the allowFrom setting.

     * A drag/resize/gesture is started only If the target of the
     * `mousedown`, `pointerdown` or `touchstart` event or any of it's
     * parents match the given CSS selector or Element.

https://raw.githubusercontent.com/taye/interact.js/master/interact.js

@DimitarChristoff

prolly a non-issue but:

https://github.com/taye/interact.js/blob/master/interact.js#L4134

shouldn't this be this._element.querySelector to restrict drag handles to child nodes only? there is no need to take other matching elements into consideration

@taye
Owner
taye commented Sep 4, 2014

You're right, it should only focus on the child nodes. However, the line that you mentioned is only there to test that the given string is a valid CS selector. I've implemented the behaviour in d67646e for both allowFrom and ignoreFrom.

Thanks for mentioning this!

@taye taye closed this Sep 14, 2014
@kevzlou7979

Can you give a sample code snippet about the implementation? Thanks great framework

@dpekkle
dpekkle commented Mar 22, 2016

Here's an implementation based on someone elses jsfiddle.

http://jsfiddle.net/dw3xdhch/43/

You can only drag/drop using the handle provided due to
line 2: allowFrom('.handle')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment