随机点名器

洗碗拼手气 (点名器)

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>随机洗碗点名器</title>
    <style>
        .box{
            width: 350px;
            height: 130px;
            padding: 25px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -175px;
            margin-top: -75px;
            border: 1px solid #000;
        }
        .name{
            height: 70px;
            border: 1px solid #ccc;
            text-align: center;
            font-size: 30px;
            font-weight: 700;
            line-height: 70px;
        }
        .btn{
            margin-top: 15px;
            height: 45px;
            width: 100%;
            font-size: 25px;
            outline: none;
            cursor: pointer;
            font-family: "Microsoft YaHei";
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="name" id="name">洗碗点名器</div>
        <button class="btn" id="btn" onclick="gotoRun()">开 始</button>
    </div>

    <script>
        var nameLi = ['小朋友洗碗', '颖姐姐洗碗', '老霍洗碗', '燃哥哥洗碗', '冯姐姐洗碗'];
        // 声明时间变量
        var timer = null;

        function gotoRun () {
            // 获取button元素
            var button = document.getElementById('btn');

            // 判断是开始还是结束
            if (timer === null) {
                // 开启定时
                timer = setInterval(getName, 100);
                // 把button的内容改掉
                button.innerHTML = "暂停";
            } else {
                clearInterval(timer);
                button.innerHTML = "开始";
                timer = null;
            }
        }
        function getName() {
            var index = Math.floor(Math.random() * nameLi.length) ;
            document.getElementById("name").innerHTML = nameLi[index];
        }
    </script>
</body>
</html>

 

 

转载于:https://www.cnblogs.com/vicii/p/6155305.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值