JS for 100 seconds countdown and simple clock

Source: Internet
Author: User

<! DOCTYPE html>

<meta charset= "utf-8" >

<title>100s Countdown </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: #000; margin:10px auto;padding:20px 0;}

Input{border:0;width:283px;height:50px;cursor:pointer;margin-top:20px;background:url (
) 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 ocount = document.getElementById (' Countdown '),

Oinput = ocount.getelementsbytagname (' input ') [0],

Aspan = Ocount.getelementsbytagname (' span '),

Timer = null;

Oinput.addeventlistener (' Click ', function () {

This.classname = = '? (timer = setinterval (updatetime,1000)): clearinterval (timer);

This.classname = This.classname = = = ' Cancel '? ': ' Cancel ';

},false);

function Format (a) {

return a.tostring (). replace (/^ (\d) $/, ' 0$1 ');

}

function UpdateTime () {

Console.log (aspan[0].innerhtml);

var remain = parseint (aspan[0].innerhtml.replace (/^0/, ')) *60+parseint (aspan[1].innerhtml.replace (/^0/, '));

If (remain <= 0) {

Clearinterval (timer);

Return

}

remain--;

aspan[0].innerhtml = Format (parseint (remain/60));

aspan[1].innerhtml = Format (remain%60);

}

}

</script>

<body>

<div id= "countdown" >

<span>01</span> minutes <span>40</span> seconds

<input type= "button" value= ""/>

</div>

</body>

Welcome to join 618237474, Find a group of private chat, send a huge amount of study materials free to send

JS for 100 seconds countdown and simple clock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.