switch_on

by Doeke Wartena

HTML

<h1 id="title" class="off">
Shooting<br>
Ourselves
</h1>
<h1 id="title">
---------------
</h1>

CSS

body {
  background: black;
}

#title {
  color: white;
}

.off {
  visibility: hidden;
}

.on {
  visibility: initial;
}

JavaScript

$(function() {
  
  // ----------------------------
  
  var trigger_with_delays = function(delays, callback, index) {
  	    
    if (index == undefined) index = 0;
    if (index > 0) callback(index-1);
    
    if (index < delays.length) {
      setTimeout(function(){trigger_with_delays(delays, callback, index+1)}, delays[index]);
    }
  }
  
  // ----------------------------
  
  var time_outs = [1500, 300, 300, 200, 200, 100, 100, 50, 50, 50, 50];
 
  trigger_with_delays(time_outs, function(index) {
  		var do_toggle_on = index % 2 == 0;
  		if (do_toggle_on) $("#title").removeClass("off");
    	else $("#title").addClass("off");
  });
  
  // ----------------------------

  console.log("done");

});