Skip to content

Instantly share code, notes, and snippets.

@ssougnez
Created June 9, 2018 22:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ssougnez/1f95d1107b28666c78a7e13301c365e3 to your computer and use it in GitHub Desktop.
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