bower install periodic.js
- requestAnimationFrame - you'll need this to support legacy browsers.
var periodic = PeriodicJS();
periodic.setup({
duration: 5000, // in milliseconds - defaults to 1 minute,
displaySelector: '.updater' // defaults to .periodicjs
update: function() {
// this function will run every <duration> milliseconds
doSomething();
}
});
function doSomething() {
// do something here
// resume periodic
periodic.run();
}
// finally, start the whole thing
periodic.run();
Also add an element with the displaySelector
class you provided earlier:
<p class='updater'></p>
Call stop()
when you want to stop:
periodic.stop();
See index.html
for a full example.
MIT © The Boston Globe