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>

  • 相关阅读:
    使用手机重量加速器
    改变 Pivot 的 HeaderTemplate
    页面构造函数和 Load 事件的执行次数
    给 ListBox 的 DataTemplate 模板中的 元素设置动画
    在ItemsControl 中,添加头部下拉更新
    (转) Unix 时间戳 与 .NET 时间转换
    图片保存到本机(链接)
    IsHitTestVisible="False" 的功能
    回到顶部按钮
    ssh访问服务器端visdom
  • 原文地址:https://www.cnblogs.com/ngdty/p/9487730.html
Copyright © 2011-2022 走看看