学习js第二周

锅打灰太狼上下的部分代码

html代码部分

<head>

        <meta charset="utf-8">

        <title>锅打灰太狼</title>

        <link rel="stylesheet" type="text/css" href="./css/day01.css"/>

    </head>

    <body>

        <div class="boss">

            <!-- 第一层开始游戏 -->

            <div class="box1">

                <p>锅打灰太狼</p>

                <button type="button">开始游戏</button>

                <div class="clearfix box1_img">

                    <img class="box1_img1" src="./img/x5.png" alt="">

                    <img class="box1_img2" src="./img/h6.png" alt="">

                </div>

            </div>

            <!-- 第二层锅打灰太狼界面 -->

            <div class="box2">

                <!-- <img class="box1_img1" src="./img/h0.png" alt=""> -->

            </div>

            <!-- 第三层再来一次 -->

            <div class="box3">

                第三层再来一次

            </div>

        </div>

    </body>

    <script type="text/javascript" src="./js/day01.js"></script>

js部分

// html加载完成后再加载js

window.onload = function(){

    // 获取第一个界面

    var box1 = document.querySelector(".box1");

    // 获取第二个界面

    var box2 = document.querySelector(".box2");

    // 获取第三个界面

    var box3 = document.querySelector(".box3");

    // 获取开始游戏按钮

    var start = document.querySelector(".box1 button");

    

    var htlImg = document.createElement("img");

    htlImg.style.position = "absolute";

    htlImg.style.top = "160px";

    htlImg.style.left = "17px";

    box2.appendChild(htlImg);

    

    var htlNum = 0;

    //灰太狼上升动画

    function htlTop(){

        var dsqHtlTop = setInterval(function(){

            htlNum++;

            if(htlNum==5){

                clearInterval(dsqHtlTop);

                htlDow();

            }

            htlImg.src = "./img/h"+htlNum+".png";

            console.log(htlNum);

        },120);

    }

    //灰太狼下降动画

    function htlDow(){

        var dsqHtlDow = setInterval(function(){

            htlNum--;

            if(htlNum==0){

                clearInterval(dsqHtlDow);

                box2.removeChild(htlImg);

            }

            htlImg.src = "./img/h"+htlNum+".png";

            console.log(htlNum);

        },100);

    }

    // 开始游戏

    start.onclick = function(){

        box1.style.display="none";

        box2.style.display="block";

        box3.style.display="none",

        htlTop();

    }

}

css部分

* {

    margin: 0;

    padding: 0;

}

.clearfix::after {

    content: "";

    display: block;

    overflow: hidden;

    clear: both;

    height: 0;

}

.clearfix{

    zoom: 1;

}

a {

    text-decoration: none;

}

ul li {

/* 清除默认样式 */

    list-style: none;

}

.boss {

/* 定义父亲*/

    width: 320px;

    height: 480px;

    margin: 0 auto;/* 水平居中*/

}

.box1 {

    width: 100%;

    height: 100%;

    background: #00b0ff;

    border-radius: 10px;

    overflow: hidden;

}

.box1 p {

    color: #ffa600;

    font-size: 40px;

    font-weight: 700;

    text-align: center;

    margin-top: 120px;

}

.box1 button {

    width: 180px;

    height: 50px;

    background: red;

    font-size: 30px;

    font-weight: 700;

    color: #fff;

    border-radius: 10px;

    border: none;

    margin: 50px auto;

    display: block;

}

.box1_img {

    margin-top: 105px;

}

.box1_img1 {

    float: left;

    margin-left: 20px;

}

.box1_img2 {

    float: right;

    margin-right: 20px;

}

.box2,.box3 {

    display: none;/* 为了显示功能*/

}

.box2 {

    width: 100%;

    height: 100%;

    background: url(../img/game_bg.jpg);/* 图片地址*/

    position: relative;/* 相对定位*/

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值