Created
June 9, 2018 22:59
-
-
Save ssougnez/1f95d1107b28666c78a7e13301c365e3 to your computer and use it in GitHub Desktop.
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
import { fromEvent } from "rxjs"; | |
import { debounceTime, map } from "rxjs/operators"; | |
let span = document.querySelector("#span-location"); | |
let button = document.querySelector("#btnStop"); | |
let subscription = fromEvent(document, "mousemove") | |
.pipe( | |
map((e) => { | |
return { x: e.clientX, y: e.clientY }; | |
}), | |
debounceTime(100) | |
) | |
.subscribe((e) => { | |
span.innerHTML = `X: ${e.x} - Y: ${e.y}`; | |
}); | |
button.addEventListener("click", (event) => subscription.unsubscribe()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment