html中加入一个计时器,HTML+CSS+JS一个简易的计时器

一个粗糙的计时器,javascript

HTML部分:css

00

:

00

:

00

开始

暂停

CSS部分:html

*{

margin:0;

padding:0;

}

.wrap{

width:300px;

height:300px;

border-radius:50%;

position:absolute;

top:calc(50% - 150px);

left:calc(50% - 150px);

box-shadow: 0 0 9px red;

}

#timer{

position:absolute;

top:90px;

left:60px;

font-size:38px;

}

#btn{

position:absolute;

top:180px;

left:70px;

font-size:30px;

}

#btn button{

width:80px;

font-size:28px;

text-align: center;

cursor: pointer;

}

JS部分:java

window.onload = function(){

var hours = document.getElementById("hours"),

minute = document.getElementById("minute"),

second = document.getElementById("second"),

begin = document.getElementById("begin"),

pause = document.getElementById("pause"),

timer = null,

Hours = 0,

Minute = 0,

Second = 0;

begin.onclick = function(){

timer = setInterval(function(){

Second++;

if(Second > 59){

Second = 0;

Minute++;

if(Minute >59){

Minute = 0;

Hours++;

}

}

if(Second < 10){

second.innerText = "0" + Second;

}else{

second.innerText = Second;

}

if(Minute < 10){

minute.innerText = "0" + Minute;

}else{

minute.innerText = Minute;

}

if(Hours < 10){

hours.innerText = "0" + Hours;

}else{

hours.innerText = Hours;

}

},1000)

}

pause.onclick = function(){

clearInterval(timer);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值