JSFiddle - React, Tailwind, and code Playground
HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<meta name="description" content="" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="generator" content="" />
<script type="text/javascript">
/* delete all between /*<demo*/ /*demo>*/
/* tags before using it ...*/
var Countdown =
{
focus : 1,
init:function(sec){
if(window.addEventListener){
window.addEventListener("focus",function(){Countdown.windowFocus(1);});
window.addEventListener("blur",function(){Countdown.windowFocus(0);});
}else if(window.attachEvent){
window.attachEvent("focus",function(){Countdown.windowFocus(1);});
window.attachEvent("blur",function(){Countdown.windowFocus(0);});
}
this._start(sec);
/*<demo*/this.windowFocusDemo()/*demo>*/
},
/*<demo*/windowFocusDemo:function(){/*just a demo for the window focus event*/document.getElementById('windowFocus').innerHTML = 'windowFocus: '+this.focus;return;},/*demo>*/
windowFocus:function(val){
this.focus = (val===1)?1:0;
this.toggle(val);
/*<demo*/this.windowFocusDemo()/*demo>*/
},
config:function(sec)
{
this.ticker = (this.ticker)?clearInterval(this.ticker):false;
this.sec = parseInt(sec);
this.full = this.sec;
this._continue = false;
this.num = document.getElementById('countdown');
this.bar = document.getElementById('countdownbar');
this.intervalMethod = 'Countdown.tick()';
this.interval = 1000;
this.barStat = 'norm';
return;
},
_start:function(sec)
{
this.config(sec);
this.ticker = setInterval(this.intervalMethod,this.interval);
return;
},
tick:function()
{
if(this.sec >= 0){
...