Started using RxJs. Can't find a way around this problem. I have a draggable control:
startDrag = rx.Observable.fromEvent(myElem,'mousedown')
now, because the control is too small mousemove
and mouseup
events should be at document level (otherwise it won't stop dragging unless cursor exactly on the element)
endDrag = rx.Observable.fromEvent document,'mouseup'
position = startDrag.flatMap ->
rx.Observable.fromEvent document,'mousemove'
.map (x)-> x.clientX
.takeUntil endDrag
now how do I "catch" the right moment when is not being dragged anymore (mouseup
).
you see the problem with subscribing to endDrag
? It will fire every time clicked anywhere, and not just myElem
How do I check all 3 properties at once? It should take only those document.mouseups that happened exactly after startDrag
and position
Upd: I mean the problem is not with moving the element. That part is easy - subscribe to position
, change element's css.
My problem is - I need to detect the moment of mouseup
and know the exact element that's been dragged (there are multiple elements on the page). How to do that I have no idea.