女神想玩,花十分钟写了一个demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="father">
<div>
<h3>时间<span id="show"></span></h3>
</div>
<button onmousedown="down()" onmouseup="up()">小王按这里</button>
</div>
</body>
<script>
let time = 0
let timeCount = null
function down() {
time = 0
let show = document.getElementById("show")
show.innerHTML = time
timeCount = setInterval(() => {
time++
}, 1)
console.log(time)
}
function up() {
let show = document.getElementById("show")
show.innerHTML = time
if(time>100){
alert("时间过长~")
}else if(time==100){
alert("太准了你!")
}else if(time>=90&&time<100){
alert("很接近了,加油")
}else{
alert("再接再厉~")
}
console.log(time)
clearInterval(timeCount)
}
</script>
<style>
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#father {
display: flex;
justify-content: center;
width: 100%;
height: 100%;
align-items: center;
flex-direction: column ;
}
button {
border-radius: 50%;
width: 150px;
height:150px;
border:none;
background-color: rgb(180, 236, 236);
box-shadow: 0px 10px 50px rgb(245, 245, 202);
}
</style>
</html>
不要做舔狗