zoukankan      html  css  js  c++  java
  • 打字小游戏

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style type="text/css">
            *{margin: 0;padding: 0;}
            div{font-size: 60px;position: absolute;}
        </style>
    </head>
    <body>
        <h2 id="score">得分:0</h2>
    </body>
    </html>
    <script>
    var timer=null;
    setInterval(function(){
        var div=document.createElement("div");
        var n=String.fromCharCode(parseInt(65+Math.random()*26));
        div.innerText=n;
        div.style.top=0;
        div.style.left=parseInt(200+Math.random()*900)+"px";
        document.body.appendChild(div);
        move(div)
    },1000)                                              //设置再页面顶部随机出现字母

    function move(obj){
        setInterval(function(){
            var speed=2;
            if(obj.offsetTop>500){
                obj.remove();
            }
            obj.style.top=obj.offsetTop+speed+"px";        
        },30)
    }                                                 //设置往下掉的速度 每30MS下掉2PX
    var oScore=document.getElementById("score");
    var num=0;
    document.onkeypress=function(e){
        var aDiv=document.getElementsByTagName("div")
        var e=e||event;
        var code=e.keyCode||e.which;
        for(i=0;i<aDiv.length;i++){
            var code1=aDiv[i].innerText.charCodeAt(0);
            if(code1==code){
                num++;
                aDiv[i].remove();
                oScore.innerText="得分"+num;
                break;
            }
        }
    }
    </script>

  • 相关阅读:
    Django model中的内嵌类(Class Meta)
    drf框架(二)
    drf框架(一)
    html、CSS 简单回顾
    前端vue框架(五)
    前端vue框架(四)
    前端Vue框架(三)
    前端vue框架(二)
    前端开发Vue框架(二)
    mysql 比较两个日期的时间差
  • 原文地址:https://www.cnblogs.com/ngdty/p/9487730.html
Copyright © 2011-2022 走看看