You are most there:
function waitForMouseStop(callback) {
var timer;
function stoppedMoving(evt) {
document.onmousemove = null;
callback();
}
function moveHandler(evt) {
evt = evt || window.event;
if (timer) {
window.clearTimeout(timer);
}
timer = window.setTimeout(function() {
stoppedMoving(evt);
}, 500);
}
document.onmousemove = moveHandler;
}
waitForMouseStop(function() {
alert("Stopped");
});
source
share