Based on my understanding of your needs, you will have to monitor both the mouse entering and leaving the element, then utilize an operator like scan
to calculate the total time. One way to achieve this is by capturing the timestamp of the mouseover
event and then sampling on the mouseout
event:
var result = document.getElementById('result');
var mouseOver = Rx.Observable.fromEvent(result, 'mouseover');
var mouseOut = Rx.Observable.fromEvent(result, 'mouseout');
mouseOver
//Record the time when mouseover occurs
.timestamp()
//Wait for mouseOut event to trigger
.sample(mouseOut)
//Retrieve only the timestamp value
.pluck('timestamp')
//Obtain a new timestamp (after mouse out)
.timestamp()
//Calculate the time interval
.map(x => x.timestamp - x.value)
//Add the new time interval to the running total
.scan((total, diff) => total += diff, 0)
.subscribe(x => console.log(x));