Skip to content

Instantly share code, notes, and snippets.

View nylki's full-sized avatar

Tom Brewe nylki

View GitHub Profile
@nylki
nylki / interval.js
Created June 15, 2020 16:23 — forked from ncou/interval.js
setTimeout and setInterval with pause and resume
// http://stackoverflow.com/questions/7279567/how-do-i-pause-a-window-setinterval-in-javascript
function RecurringTimer(callback, delay) {
var timerId, start, remaining = delay;
this.pause = function() {
window.clearTimeout(timerId);
remaining -= new Date() - start;
};