Last active
April 24, 2020 09:52
-
-
Save avaforvr/7393259d6679df05b53e4bc14f5dfa0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const requestAnimFrame = (function() { | |
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { | |
return window.setTimeout(callback, 1000 / 60, (new Date).getTime()) | |
}; | |
})(); | |
const cancelAnimFrame = function() { | |
return window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || function(id) { | |
clearTimeout(id); | |
}; | |
}(); | |
let requestId; | |
let record = 0; | |
const interval = 1000; | |
const step = function(timestamp) { | |
const past = timestamp - record; | |
if (past >= interval) { | |
console.log(past); | |
record = timestamp; | |
} else { | |
console.log('wait'); | |
} | |
requestId = requestAnimFrame(step); | |
}; | |
requestId = requestAnimFrame(step); | |
$('.header-bar-main').on('click.clear', function() { | |
cancelAnimFrame(requestId); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment