var waiter = function (selector, framerate, patterns) {
var element = document.querySelectorAll(selector)[0];
element.style.css = "display: none";
var timer, frame;
return {
tick: function () {
element.innerHTML = '[' + patterns[frame].replace(/\s/g, ' ') + ']';
frame = ++frame % patterns.length;
},
show: function () {
frame = 0;
if (timer)
window.clearInterval(timer);
timer = window.setInterval(function () {
this.tick();
}.bind(this), framerate);
element.style.css = "display: block";
},
}
};
waiter('#waiter', 50, [
'> -------',
'>> ------',
' >> -----',
'- >> ----',
'-- >> ---',
'--- >> --',
'---- >> -',
'----- >> ',
'------ >>',
'------- >',
'------- <',
'------ <<',
'----- << ',
'---- << -',
'--- << --',
'-- << ---',
'- << ----',
' << -----',
'<< ------',
'< -------',
]).show();
waiter('#waiter2', 50, [
'> -------',
'>> ------',
' >> -----',
'- >> ----',
'-# >> ---',
'-#- >> --',
'-#-# >> -',
'-#-#- >> ',
'-#-#-# >>',
'-#-#-#- >',
'-#-#-#- <',
'-#-#-# <<',
'-#-#- << ',
'-#-# << -',
'-#- << #-',
'-# << -#-',
'- << #-#-',
' << -#-#-',
'<< #-#-#-',
'< -#-#-#-',
'> -#-#-#-',
'>> #-#-#-',
' >> -#-#-',
'- >> #-#-',
'-- >> -#-',
'--- >> #-',
'---- >> -',
'----- >> ',
'------ >>',
'------- >',
'------- <',
'------ <<',
'----- << ',
'---- << -',
'--- << --',
'-- << ---',
'- << ----',
' << -----',
'<< ------',
'< -------',
]).show();
waiter('#waiter3', 100, [
'> ',
'>> ',
' >> ',
'- >> ',
'-- >> ',
'--- >> ',
'---- >> ',
'----- >> ',
'------ >>',
'------- >',
'-------- ',
'---------',
'<--------',
' <-------',
'( =------',
' ( =-----',
' ( <----',
' ( <---',
' ( =--',
' ( =-',
' ( <',
' ( ',
' (',
' ',
]).show();
if (!String.prototype.x) {
String.prototype.x = function (times) {
return Array(times + 1).join(this);
}
}
var blink =
' -___- |'.x(4) +
' -___o |' +
' -___O |'.x(4) +
' -___o |' +
' -___- |' +
' o___o\' |' +
(' O___O" |'.x(2) +
' -___-" |').x(2) +
' O___O" |'.x(10) +
' -___-" |' +
' O___O |'.x(10) +
' o___o |'.x(10) +
' -___- |'.x(10) +
' -___o |'.x(16) +
' -___- |'.x(10);
waiter('#waiter4', 100, blink.replace(/^\||\|$/, '').split('|')).show();
.waiter {
font-family: Consolas, Courier;
}
<div class="waiter" id="waiter"></div>
<div class="waiter" id="waiter2"></div>
<div class="waiter" id="waiter3"></div>
<div class="waiter" id="waiter4"></div>
<button>can't be in head. Next..usingdocument.writewill wipe out the whole page if used afer page is loadeda===2?document.writeand take your<button>out of your head.