ckhatton
12/8/2014 - 11:04 PM

Alternately change a snippet of text in the DOM.

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; }
  }
}