The countdown digital clock effect of JS web pages and the countdown digital clock of js pages
The example in this article describes the digital clock effect of page countdown implemented by JS. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> countdown clock implemented by javascript </title>
<Style>
Body, div {margin: 0; padding: 0 ;}
Body {color: # fff; font: 16px/1.5 \ 5fae \ 8f6f \ 96c5 \ 9ed1 ;}
# Countdown {width: 300px; text-align: center; background: # 1a1a1a; margin: 10px auto; padding: 20px 0 ;}
Input {border: 0; width: 283px; height: 50px; cursor: pointer; margin-top: 20 PX; background: url (http://www.bkjia.com/jscss/demoimg/201210/btn-1.png) no-repeat ;}
Input. cancel {background-position: 0-50px ;}
Span {color: #000; width: 80px; line-height: 2; background: # fbfbfb; border: 2px solid # b4b4b4; margin: 0 10px; padding: 0 10px ;}
</Style>
<Script>
Window. onload = function ()
{
Var oCountDown = document. getElementById ("countdown ");
Var aInput = oCountDown. getElementsByTagName ("input") [0];
Var timer = null;
AInput. onclick = function ()
{
This. className = ""? (Timer = setInterval (updateTime, 1000), updateTime (): (clearInterval (timer ));
This. className = this. className = ''? "Cancel ":'';
};
Function format ()
{
Return a. toString (). replace (/^ (\ d) $/, '0 $1 ')
}
Function updateTime ()
{
Var aSpan = oCountDown. getElementsByTagName ("span ");
Var oRemain = aSpan [0]. innerHTML. replace (/^ 0/, '') * 60 + parseInt (aSpan [1]. innerHTML. replace (/^ 0 /,''));
If (oRemain <= 0)
{
ClearInterval (timer );
Return
}
ORemain --;
ASpan [0]. innerHTML = format (parseInt (oRemain/60 ));
ORemain % = 60;
ASpan [1]. innerHTML = format (parseInt (oRemain ));
}
}
</Script>
</Head>
<Body>
<Div id = "countdown">
<Span> 01 </span> minutes <span> 40 </span> seconds
<Input type = "button" value = ""/>
</Div> special effects on code of www.jb51.net
</Body>
</Html>
I hope this article will help you design javascript programs.