How to emit when events stop coming?

Viewed 30

I have Observable from an event of the mouse move.

I want to react when the mouse stops moving - meaning when events from Observable stop coming...

How do I do that?

1 Answers

You can use fromEvent to watch for mousemove on the document. Then use debounceTime within a pipe to wait for the mouse movement to stop.

fromEvent(document, 'mousemove')
  .pipe(debounceTime(2000))
  .subscribe(() => console.log('Mouse Stopped: No movement for 2s'));
Related