码迷,mamicode.com
首页 > 其他好文 > 详细

【原生】游戏中的倒计时效果

时间:2020-05-22 00:12:46      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:weight   var   info   splay   code   UNC   width   gray   name   

代码

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>倒计时</title>
        <style type="text/css">
            * {
                margin: 0;
                padding: 0;
            }

            body {
                width: 100%;
                height: 100%;
            }

            #box {
                position: absolute;
                top: 50%;
                left: 50%;
                width: 600px;
                height: 100px;
                margin-top: -50px;
                margin-left: -300px;
                text-align: center;
                line-height: 100px;
                font-size: 26px;
                font-weight: 700;
                font-family: "黑体";
                color: gray;
            }

            #box .seconds {
                display: inline-block;
                width: 50px;
                height: 50px;
                font-size: 48px;
                text-align: center;
                line-height: 50px;
                animation: animate 1s infinite;
            }

            @keyframes animate {
                from {
                    font-size: 48px;
                }

                to {
                    font-size: 24px;
                }
            }
        </style>
        <script type="text/javascript">
            window.onload = function() {
                var box = document.getElementById("box");
                var seconds = document.getElementsByClassName("seconds")[0];
                seconds.innerText = "5";

                var timer = setInterval(function() {
                    seconds.innerText = parseInt(seconds.innerText) - 1;

                    if (parseInt(seconds.innerText) < 0) {
                        clearInterval(timer);
                        box.innerHTML = "全军出击";
                    }
                }, 1000);
            }
        </script>
    </head>
    <body>
        <div id="box">
            敌军还有<i class="seconds"></i>秒到达战场...
        </div>
    </body>
</html>

 

效果

技术图片

【原生】游戏中的倒计时效果

标签:weight   var   info   splay   code   UNC   width   gray   name   

原文地址:https://www.cnblogs.com/lightbc/p/12934262.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!