【原生JS】做一个打字消除小游戏,学习摸鱼两不误

简介: 【原生JS】做一个打字消除小游戏,学习摸鱼两不误
+关注继续查看

话不多说先看效果!

2023-04-16.png


JS打字消除游戏

页面布局:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打字消消乐</title>
     <!-- 这里我使用u-reset来清除一些默认样式 -->
    <link rel="stylesheet" href="./css/u-reset.min.css">
    <link rel="stylesheet" href="./css/index.css">
    <script src="./js/index.js"></script>
</head>
<body>
    <!-- 开始界面开始 -->
    <div class="start">
        <div class="start-aom">
            <img src="./img/start/girl.png" alt="" class="girl">
            <img src="./img/start/text.png" alt="" class="title">
        </div>
        <img src="./img/start/play.png" alt="" class="playbtn">
    </div>
    <!-- 开始界面结束 -->
    <!-- 加载界面开始 -->
    <div class="load">
        <div class="loading">
            <div class="loadTiao">
                <div class="progresscon">
                    <span></span>
                </div>
            </div>
        </div>
    </div>
    <!-- 加载界面结束 -->
    <!-- 游戏开始 -->
    <div class="plays">
        <div class="main"></div>
        <div class="fenshu">
            <span></span>
        </div>
        <div class="xuetiao">
            <div class="xuetiao1"></div>
        </div>
        <img src="./img/play/close.png" class="close" alt="">
        <audio src="./于荣光 - 少林英雄.mp3"></audio>
    </div>
    <!-- 游戏结束 -->
</body>
</html>

CSS样式:

html,body{
    width: 100%;
    height: 100%;
}
.start{
    width: 100%;
    height: 100%;
    background: url(../img/start/bg.png) no-repeat center center/cover;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10000;
    transition: all 1s;
    /* display: none; */
}
.start-aom{
    width: 400px;
    height: 400px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.girl{
    width: 250px;
    height: 250px;
    display: block;
    margin: 0 auto;
    transform: translateY(70px);
    animation: jump 1s;
}
 @keyframes jump{
    0%{
        transform: translateY(0px);
    }
    50%{
        transform: translateY(160px);
    }
    100%{
        transform: translateY(0px);
    }
}
.title{
    width: 400px;
    height: 200px;
    display: block;
    /* margin: 0 auto; */
    position: relative;
    z-index: 1000;
}
.playbtn{
    width: 50px;
    height: 50px;
    display: block;
    position: absolute;
    right: 0;
    left: 0;
    margin: auto;
    bottom: 50px;
    animation: run 1s infinite;
}
.playbtn:hover{
    cursor: pointer;
}
@keyframes run{
    0%{
        transform: translateY(0px);
    }
    50%{
        transform: translateY(20px);
    }
    100%{
        transform: translateY(0px);
    }
}
/* 加载界面开始 */
.load{
    width: 100%;
    height: 100%;
    background: url(../img/load/bg.png) no-repeat center/cover;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;
    transition: all 1s;
    /* display: none; */
    z-index: 1000;
}
.loading{
    width: 500px;
    height: 500px;
    background: url(../img/load/loading1.png) center no-repeat;
    background-size: 100% auto ;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    /* display: none; */
}
.loadTiao{
    width: 303px;
    height: 39px;
    background: url(../img/load/loadingProgress.png) center no-repeat;
    background-size: 100% auto;
    display: block;
    margin: 220px auto 0;
    position: relative;
}
.progresscon{
    width: 0px;
    height: 19px;
    background: url(../img/load/progresscon.png);
    position: absolute;
    left: 5px;
    top: 9px;
    border-radius: 15px;
}
.progresscon span{
    text-align: center;
    width: 303px;
    display: block;
}
/* 加载界面结束 */
/* 游戏开始 */
.plays{
    width: 100%;
    height: 100%;
    background:url(../img/play/bg.png) center/cover no-repeat ;
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
    z-index: 999;
}
.main{
    width: 100%;
    height: 100px;
    position: relative;
    z-index: 10;
    float: left;
    transition: all 5s;
}
.main img{
    transition: all 0.2s;
}

.xuetiao{
    width: 204px;
    height: 48px;
    background: url(../img/play/life.png) center no-repeat;
    background-size: contain;
    z-index: 100;
    float: left;
    position: absolute;
    top: 19px;
    left: 194px;
}
.xuetiao1{
    width: 132px;
    height: 24px;
    background-color: rgb(224, 31, 31);
    position: absolute;
    top: 13px;
    left: 60px;
    border-radius: 7px;
}
.fenshu{
    width: 168px;
    height: 53px;
    background: url(../img/play/fenzhi.png) center no-repeat;
    background-size: contain;
    z-index: 100;
    position: absolute;
    top: 10px;
    left: 10px;
}
.fenshu span{
    font-size: 20px;
    color: #fff;
    display: block;
    margin-top: 21px;
    margin-left: 95px;
}
.close{
    position: absolute;
    top: 10px;
    right: 10px;
    width: 50px;
    height: 50px;
    z-index: 1000;
}
/* 游戏结束 */

JS文件(重点):

html,body{
    width: 100%;
    height: 100%;
}
.start{
    width: 100%;
    height: 100%;
    background: url(../img/start/bg.png) no-repeat center center/cover;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10000;
    transition: all 1s;
    /* display: none; */
}
.start-aom{
    width: 400px;
    height: 400px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.girl{
    width: 250px;
    height: 250px;
    display: block;
    margin: 0 auto;
    transform: translateY(70px);
    animation: jump 1s;
}
 @keyframes jump{
    0%{
        transform: translateY(0px);
    }
    50%{
        transform: translateY(160px);
    }
    100%{
        transform: translateY(0px);
    }
}
.title{
    width: 400px;
    height: 200px;
    display: block;
    /* margin: 0 auto; */
    position: relative;
    z-index: 1000;
}
.playbtn{
    width: 50px;
    height: 50px;
    display: block;
    position: absolute;
    right: 0;
    left: 0;
    margin: auto;
    bottom: 50px;
    animation: run 1s infinite;
}
.playbtn:hover{
    cursor: pointer;
}
@keyframes run{
    0%{
        transform: translateY(0px);
    }
    50%{
        transform: translateY(20px);
    }
    100%{
        transform: translateY(0px);
    }
}
/* 加载界面开始 */
.load{
    width: 100%;
    height: 100%;
    background: url(../img/load/bg.png) no-repeat center/cover;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;
    transition: all 1s;
    /* display: none; */
    z-index: 1000;
}
.loading{
    width: 500px;
    height: 500px;
    background: url(../img/load/loading1.png) center no-repeat;
    background-size: 100% auto ;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    /* display: none; */
}
.loadTiao{
    width: 303px;
    height: 39px;
    background: url(../img/load/loadingProgress.png) center no-repeat;
    background-size: 100% auto;
    display: block;
    margin: 220px auto 0;
    position: relative;
}
.progresscon{
    width: 0px;
    height: 19px;
    background: url(../img/load/progresscon.png);
    position: absolute;
    left: 5px;
    top: 9px;
    border-radius: 15px;
}
.progresscon span{
    text-align: center;
    width: 303px;
    display: block;
}
/* 加载界面结束 */
/* 游戏开始 */
.plays{
    width: 100%;
    height: 100%;
    background:url(../img/play/bg.png) center/cover no-repeat ;
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
    z-index: 999;
}
.main{
    width: 100%;
    height: 100px;
    position: relative;
    z-index: 10;
    float: left;
    transition: all 5s;
}
.main img{
    transition: all 0.2s;
}

.xuetiao{
    width: 204px;
    height: 48px;
    background: url(../img/play/life.png) center no-repeat;
    background-size: contain;
    z-index: 100;
    float: left;
    position: absolute;
    top: 19px;
    left: 194px;
}
.xuetiao1{
    width: 132px;
    height: 24px;
    background-color: rgb(224, 31, 31);
    position: absolute;
    top: 13px;
    left: 60px;
    border-radius: 7px;
}
.fenshu{
    width: 168px;
    height: 53px;
    background: url(../img/play/fenzhi.png) center no-repeat;
    background-size: contain;
    z-index: 100;
    position: absolute;
    top: 10px;
    left: 10px;
}
.fenshu span{
    font-size: 20px;
    color: #fff;
    display: block;
    margin-top: 21px;
    margin-left: 95px;
}
.close{
    position: absolute;
    top: 10px;
    right: 10px;
    width: 50px;
    height: 50px;
    z-index: 1000;
}
/* 游戏结束 */
目录
相关文章
|
2月前
|
机器学习/深度学习 前端开发 JavaScript
猜数字小游戏但多语言版本(C、Java、Golang、python、JavaScript)
猜数字小游戏但多语言版本(C、Java、Golang、python、JavaScript)
|
3月前
|
人工智能 前端开发 JavaScript
原生JavaScript抒写——贪吃蛇小游戏
前端开发的核心逻辑思维,莫过于就是对JavaScript的掌握了,不管是小程序还是主流框架都是在原生JavaScript的基础上延伸和简便,因此原生JavaScript对于前端是必须要掌握和不断学习的,那么好,今天我们就来用原生的JavaScript写一个简单的小游戏——贪吃蛇
40 1
 原生JavaScript抒写——贪吃蛇小游戏
|
5月前
|
缓存 JavaScript 前端开发
纯JavaScript入门级小游戏:兔子抢金币(附演示地址+源码)
Hello,大家好,我是兔哥,我又来分享好玩的入门级项目啦。 今天给大家带来的是一个纯JavaScript入门级小游戏:兔子抢金币,规则非常简单,控制屏幕上的兔子去接天上掉下来的金币,接满20个就可以通关。
|
8月前
|
存储 前端开发
html+css+javascript实现小游戏2048(详解,附源代码)
1.上下左右的移动原理相同,这里只详细说明向上移动的方法 2.这里的上下左右由wasd四个键控制 3…小方块空的意思就是没数字,空白
178 0
html+css+javascript实现小游戏2048(详解,附源代码)
|
9月前
|
JavaScript C语言 Python
好玩的小游戏系列 (一)基于html+js 原生贪吃蛇
好玩的小游戏系列 (一)基于html+js 原生贪吃蛇
88 0
好玩的小游戏系列 (一)基于html+js 原生贪吃蛇
|
10月前
|
JavaScript 前端开发
HTML+CSS+JAVASCRIPT实现——球球坠落小游戏
本文主要介绍如何使用HTML三件套来实现制作一个网页小游戏-----球球坠落,玩家需要控制键盘来移动小球落在不断上升的台阶上,避免碰到最顶部或者掉进悬崖中,看能持续多久时间,获得更高的得分
168 0
HTML+CSS+JAVASCRIPT实现——球球坠落小游戏
|
人工智能 JavaScript 算法
通过JS实现一个带AI的井字棋小游戏
用JavaScript做一个井字棋的小游戏玩玩
231 0
|
JavaScript
利用JS实现猜数字小游戏
利用JS实现猜数字小游戏
利用JS实现猜数字小游戏
|
JavaScript 定位技术
js 简单的推箱子小游戏步骤解析--大家都玩过的
推箱子小游戏大家肯定都玩过,之所以写这篇文章,是觉得这个小游戏足够简单好理解,大家看完文章之后,自己也能花上半天功夫敲出一个推箱子小游戏来,如果喜欢的话可以点波赞,或者关注一下,希望本文可以帮到大家。 本文首发于我的个人blog:obkoro1.com demo:推箱子小游戏 步骤解析: 本文代码已经放在了github上面了,里面也进行了很详细的代码注释,可以copy下来,在本地运行一下看看。
243 0
js 简单的推箱子小游戏步骤解析--大家都玩过的
|
JavaScript 前端开发 Java
【零基础入门 HTML + CSS + JavaScript 实现打地鼠小游戏】 闲暇时刻玩一玩 轻松丢烦恼~
【零基础入门 HTML + CSS + JavaScript 实现打地鼠小游戏】 闲暇时刻玩一玩 轻松丢烦恼~
247 0
【零基础入门 HTML + CSS + JavaScript 实现打地鼠小游戏】 闲暇时刻玩一玩 轻松丢烦恼~
热门文章
最新文章
相关产品
云迁移中心
推荐文章
更多