原生JS实现的跳一跳小游戏完整实例

本文提供了一个使用原生JavaScript实现的跳一跳小游戏实例,详细介绍了如何生成随机地图以及处理按住按钮后的动作和判断逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文实例讲述了原生JS实现的跳一跳小游戏。分享给大家供大家参考,具体如下:
小游戏–跳一跳,类似于微信的跳一跳,大体实现功能有:
1.先随机生成地图;
2.按住按钮释放后完成动作并进行判断;

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>跳一跳</title>
  <style>
    *{
    
    padding: 0;margin: 0;}
    .game{
    
    
      position: relative;
      width: 800px;
      height: 400px;
      border: 1px solid black;
      margin: 0 auto;
    }
    .game .content{
    
    
      position: absolute;
      width: 700px;
      height: 400px;
      left: 0;
      top: 0;
    }
    .game #chess{
    
    
      position: absolute;
      width: 40px;
      height: 48px;
      overflow: hidden;
      z-index:99;
      transition-property: all;
    }
    .cylinder{
    
    
      position: relative;
      width: 70px;
      height: 101px;
      float: left;
    }
    .cylinder .top{
    
    
      position: absolute;
      width: 70px;
      height: 35px;
      border-radius: 50%;
      background: yellow;
      z-index: 4;
    } 
    .cylinder .front{
    
    
      position: absolute;
      width: 70px;
      height: 70px;
      background: black;
      margin-top: 17px;
      z-index: 3;
    }
    .cylinder .bottom{
    
    
      position: absolute;
      width: 70px;
      height: 35px;
      border-radius: 50%;
      background: black;
      margin-top: 65px;
      z-index: 4;
    }
    button{
    
    
      position: absolute;
      width: 80px;
      height: 30px;
      font-size: 16px;
      text-align: center;
      line-height: 30px;
      border-radius: 20%;
      bottom: 10px;
      right: 10px;
    }
    .move{
    
    
      animation-name: jump;
    }
    /* 跳棋运动动画 */
    @keyframes jump{
    
    
      0%{
    
    transform: rotate(0deg);}
      10%{
    
    transform: rotate(36deg);}
      20%{
    
    transform: rotate(72deg);}
      30%{
    
    transform: rotate(108deg)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值