js按钮点击持续时间(一个demo)

女神想玩,花十分钟写了一个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>

不要做舔狗

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值