• 打子弹游戏 js


    <table id="table">
        <tr>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
        </tr>
    </table>
    <div class="box" id="box"></div>
    
    css
    
    
    #table td{
         20px;
        height: 20px;
    }
    .box {
         20px;
        height: 20px;
        background: red;
        position: absolute;
        bottom: 0px;
        left: 0px;
    }
    
    .gun {
         20px;
        height: 10px;
        position: absolute;
        bottom: 10px;
        left: 20px;
        background: green;
    }
    
    js
    
    var table=document.getElementById('table');
    var box=document.getElementById('box');
    /*create table lines*/
    /*var timer1=null;
    timer1=setInterval(function () {
        var tr=document.createElement('tr');
        for(var i=0;i<20;i++){
            var td=document.createElement('td');
            td.innerHTML=1;
            tr.appendChild(td);
        }
        table.getElementsByTagName('tbody')[0].insertBefore(tr,table.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[0]);
    },3000);*/
    /*move the box*/
    document.onkeydown = function (e) {
        var keycode = e.keyCode;
        switch (keycode){
            case 37:
                $('#box').css('left','-=20');
                break;
            case 39:
                $('#box').css('left','+=20');
                break;
        }
        if(parseInt($('#box').css('left'))<=0){
            $('#box').css('left',0);
        }
    };
    
    /*create gun to shoutdown*/
    var timer2=null;
    timer2=setInterval(function () {
        var gun=document.createElement('div');
        gun.className='gun';
        gun.style.bottom=10+'px';
        gun.style.left=$('#box').css('left')
        document.body.appendChild(gun);
        $(gun).animate({
            'bottom': window.innerHeight-10+"px",
            'left':$('#box').css('left')
        }, 500, function () {
            var Num = parseInt(gun.style.left) / 20;
            $('td').eq(Num).html('');
            document.body.removeChild(gun);
        });
    },5100);
  • 相关阅读:
    获取DIV与浏览器顶部相聚一定位置之后移动DIV
    CSS定位小技巧
    jquery动态样式操作
    Python学习笔记1
    KNN算法的感受 2
    KNN算法的感受 1
    Matplotlib安装感想
    安装numpy只需一步简单的方法
    Ubuntu学习笔记3-图书知识点总结
    Hadoop源码如何查看
  • 原文地址:https://www.cnblogs.com/wz0107/p/4878777.html
Copyright © 2020-2023  润新知