Last active
August 29, 2015 14:15
-
-
Save mg/166062ed5959e4854ec2 to your computer and use it in GitHub Desktop.
Rx.js snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Drag & Drop | |
*/ | |
var parent= document.getElementById('parent'); | |
var widget= document.getElementById('widget'); | |
var mouseDowns= Observable.fromEvent(widget, 'mousedown'); | |
var parentMouseMoves= Observable.fromEvent(parent, 'mousemove'); | |
var parentMouseUp= Observable.fromEvent(parent, 'mosueup'); | |
var drags= | |
mouseDowns. | |
map(function(e) { | |
return parentMouseMoves. | |
takeUntil(parentMouseUps); | |
}). | |
concatAll(); | |
drags.forEach(function(e) { | |
widget.style.left= e.clientX + 'px'; | |
widget.style.top= e.clientY + 'px'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment