jq打字游戏

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            *{
                margin: 0px;
                padding: 0px;
            }
            .zimu{
                width: 30px;
                height: 30px;
                position: absolute;
                border-radius: 50%;
                text-align: center;
            }
            
        </style>
    </head>
    <body>
    <span id="count"></span>
    </body>
    <script src="js/jquery-1.11.0.js"></script>
    <script>
        var score = 0;
            function ran(max,min){
                return Math.round(Math.random()*(max-min)+min);
            }
                
            $(function(){
                function create(){
            var r = ran(255,0);
            var g = ran(255,0);
            var b = ran(255,0);
            var a = ran(1,0.5);
            var k = ran(90,65);
            var ch = String.fromCharCode(k);
            var left = ran(document.documentElement.clientWidth,0);
            var top = ran(document.documentElement.clientHeight,0);
            console.log(k);
            $('body').append('<span class="zimu zimu'+k+'"style="background-color: rgba('+r+','+g+','+b+','+a+');top:'+top+'px;left:'+left+'px;">'+ch+'</span>');
            }
            setInterval(create,1100);
        })
            
            $(document).keyup(function(event){
                var keycode = event.keyCode;
                $(".zimu"+keycode).animate({
                    'top':+200,
                    'opacity':0,
                },'slow')
                $(".zimu"+keycode).hide('slow',function(){
                    score+=20;
                    $("#count").html(score);
                    $(this).remove();
                    console.log($(".zimu").length);
                })
            })
            
    </script>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容