HTML 实现9宫格拼图小游戏


<style type="text/css">
#id {
	background;
	border:none;
}
</style>`

<body onkeydown="whichButton(event)">
    <div style="width: 480px;height: 300px;border: 2px solid #000;position: absolute;">

        <div class="lattice" id="lattice1" style="top: 0px;left: 0px;"><img src="${ctx}/jsp/9Ge/FengJing/1.jpg"></img></div>
        <div class="lattice" id="lattice2" style="top: 0px;left: 160px;"><img src="${ctx}/jsp/9Ge/FengJing/2.jpg"></img></div>
        <div class="lattice" id="lattice3" style="top: 0px;left: 320px;"><img src="${ctx}/jsp/9Ge/FengJing/3.jpg"></img></div>

        <div class="lattice" id="lattice4" style="top: 100px;left: 0px;"><img src="${ctx}/jsp/9Ge/FengJing/4.jpg"></img></div>
        <div class="lattice" id="lattice5" style="top: 100px;left: 160px;"><img src="${ctx}/jsp/9Ge/FengJing/5.jpg"></img></div>
        <div class="lattice" id="lattice6" style="top: 100px;left: 320px;"><img src="${ctx}/jsp/9Ge/FengJing/6.jpg"></img></div>

        <div class="lattice" id="lattice7" style="top: 200px;left: 0px;"><img src="${ctx}/jsp/9Ge/FengJing/7.jpg"></img></div>
        <div class="lattice" id="lattice8" style="top: 200px;left: 160px;"><img src="${ctx}/jsp/9Ge/FengJing/8.jpg"></img></div>
        <div class="lattice" id="lattice9" style="top: 200px;left: 320px;"></div>
    </div>
    <div style="width:200;height: 125px;border: 2px solid #000;position: absolute;left:500px;"><img src="${ctx}/jsp/9Ge/FengJing/FengJing1.jpg"></img></div>
    <script type="text/javascript">
        function whichButton(event) {
            var ShuZu = [1, 2, 3, 4, 5, 6, 7, 8, 9];
            var i = 0;

            //W
            if (event.keyCode == 87) {
                //W  -- 9=1
                if (lattice9.style.top == "0px" && lattice9.style.left == "0px") {
                    for (i = 0; i < ShuZu.length; i++) {
                        var Value = document.getElementById("lattice" + ShuZu[i]);
                        if (Value.style.top == "100px" && Value.style.left == "0px") {
                            Value.style.top = "0px";
                            lattice9.style.top = "100px";
                            return;
                        }
                    }
                }
                //W  -- 9=2
                if (lattice9.style.top == "0px" && lattice9.style.left == "160px") {
                    for (i = 0; i < ShuZu.length; i++) {
                        var Value = document.getElementById("lattice" + ShuZu[i]);
                        if (Value.style.top == "100px" && Value.style.left == "160px") {
                            Value.style.top = "0px";
                            lattice9.style.top = "100px";
                            lattice9.style.left = "160px";
                            return;
                        }
                    }
                }
                //W  -- 9=3
                if (l
  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值