Skip to content

Instantly share code, notes, and snippets.

@ckhatton
Created December 8, 2014 23:04
Show Gist options
  • Save ckhatton/c5ba534a0fbb09ae74d4 to your computer and use it in GitHub Desktop.
Save ckhatton/c5ba534a0fbb09ae74d4 to your computer and use it in GitHub Desktop.
Alternately change a snippet of text in the DOM.
var customInterval = null;
function changeText(elem, text) {
// 'text' is a array of strings
// For example: ['loading','.loading.','..loading..','...loading...']
var counter = 0;
customInterval = setInterval(change, 1000);
function change() {
elem.text(text[counter]);
counter++;
if(counter >= text.length) { counter = 0; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment