Tom貓小游戲功能實現

来源:https://www.cnblogs.com/original-alps/archive/2020/07/04/13234893.html
-Advertisement-
Play Games

本文章通過簡單的css和html的操作,來實現Tom貓小游戲的功能,通過簡單的js代碼,讓圖片不斷切換來實現動畫效果。 Tom貓小游戲的HTML部分: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name= ...


  本文章通過簡單的css和html的操作,來實現Tom貓小游戲的功能,通過簡單的js代碼,讓圖片不斷切換來實現動畫效果。

Tom貓小游戲的HTML部分:

  

<!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>TomCat</title> </head> <body>     <section>         <img id="imgShow" src="./tom/img/Animations/angry/angry_00.jpg" alt="">     </section>     <div class="cymbal">         <img src="./tom/img/Buttons/cymbal/cymbal.png" alt="">     </div>     <div class="drink">         <img src="./tom/img/Buttons/drink/drink.png" alt="">     </div>     <div class="eat">         <img src="./tom/img/Buttons/eat/eat.png" alt="">     </div>     <div class="fart">         <img src="./tom/img/Buttons/fart/fart.png" alt="">     </div>     <div class="pie">         <img src="./tom/img/Buttons/pie/pie.png" alt="">     </div>     <div class="scratch">         <img src="./tom/img/Buttons/scratch/scratch.png" alt="">     </div>     <div class="angry"></div>     <div class="angry1"></div>     <div class="footLeft"></div>     <div class="footRight"></div>     <div class="knockout"></div>     <div class='stomach'></div>     <div></div>
    <audio src="" id="music"></audio> </body> </html>   Tom貓的css部分:     <style>     *{         margin:0;         padding:0;     }     img{         display:block;     }     body,html{         height:100%;     }     section{         width:100%;         height:100%;     }     #imgShow{         width:100%;         height:100%;     }     .cymbal{         width:60px;         height:60px;         position:absolute;         left:1%;         bottom:30%;     }     .drink{         width:60px;         height:60px;         position:absolute;         left:1%;         bottom:20%;     }     .eat{         width:60px;         height:60px;         position:absolute;         left:1%;         bottom:10%;     }     .fart{         width:60px;         height:60px;         position:absolute;         right:1%;         bottom:30%;     }     .pie{         width:60px;         height:60px;         position:absolute;         right:1%;         bottom:20%;     }     .scratch{         width:60px;         height:60px;         position:absolute;         right:1%;         bottom:10%;     }     .angry{         width:108px;         height:92px;        /*  background:chartreuse; */         position: absolute;         left:35%;         bottom:31%;     }     .angry1{         width:38px;         height:63px;        /*  background:chartreuse; */         position: absolute;         right:22%;         bottom:11%;     }     .footLeft{         width:42px;         height:35px;        /*  background:red; */         position:absolute;         left:36%;         bottom:4%;     }     .footRight{         width:42px;         height:35px;         /* background:blue; */         position:absolute;         right:36%;         bottom:4%;     }     .knockout{         width:110px;         height:46px;        /*  background:blue; */         position:absolute;         right:36%;         bottom:76%;     }     .stomach{         width:110px;         height:88px;         /* background:yellow; */         position:absolute;         right:36%;         bottom:15%;     }     </style>   Tom貓js部分:     <script>     function Tom(){         this.imgShow = document.getElementById('imgShow');         this.btn = document.querySelectorAll('div');         this.music = document.getElementById('music');         this.init();     }     Tom.prototype = {         init : function(){             this.eventBind();         },         tomPlay : function(name,num){             var _this = this;             this.count = 0 ;             clearInterval(this.timer);             this.timer = setInterval(function(){                 if(_this.count >= num){                     clearInterval(_this.timer);                     _this.count = 0 ;                 }else{                     _this.count++;                     _this.imgShow.src = './tom/img/Animations/'+name+'/'+name+'_' + _this.mendZero(_this.count)+'.jpg';
                }             },80)         },
        mendZero : function(num){              if(num < 10){                  return '0' + num;              }else{                  return num;              }         },
        eventBind : function(){             var _this = this;             for(let i = 0 , k = this.btn.length ; i < k ; i++){                 this.btn[i].onclick = function(){                     let classN = this.className;                     switch(classN){                         case 'cymbal' :                             _this.tomPlay('cymbal',12);                             _this.music.src = './tom/mp3/pia.mp3';                             _this.music.play();                             break;                         case 'drink' :                             _this.tomPlay('drink',80);                             break;                         case 'eat' :                             _this.tomPlay('eat',39);                             break;                         case 'fart' :                             _this.tomPlay('fart',27);                             break;                         case 'pie' :                             _this.tomPlay('pie',23);                             break;                         case 'scratch' :                             _this.tomPlay('scratch',55);                             break;                         case 'angry' :                             _this.tomPlay('angry',25);                             break;                         case 'angry1' :                             _this.tomPlay('angry',25);                             break;                         case 'footLeft' :                             _this.tomPlay('footRight',29);                             _this.music.src = './tom/mp3/tomaiyou.mp3';                             _this.music.play();                             break;                         case 'footRight' :                             _this.tomPlay('footLeft',29);                             _this.music.src = './tom/mp3/tomaiyou.mp3';                             _this.music.play();                             break;                         case 'knockout' :                             _this.tomPlay('knockout',80);                             break;                         case 'stomach' :                             _this.tomPlay('stomach',33);                             _this.music.src = './tom/mp3/tomaiyou.mp3';                             _this.music.play();                             break;                     }                 }             }         }     }     new Tom();     </script> 內容如有雷同,純屬巧合,侵權請聯繫本人。
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • MySQL索引 索引分類 最左首碼原則 覆蓋索引 索引下推 聯合索引順序 What's Index ? 索引就是幫助RDBMS高效獲取數據的數據結構。 索引可以讓我們避免一行一行進行全表掃描。它的價值就是可以幫助你對數據進行快速定位。 索引分類 按照功能邏輯來分 普通索引 INDEX(col_nam ...
  • Flutter第一個應用--踩坑之路 安裝 參照官網教程(這裡)下載解壓,以及設置環境變數即可。 如果你是中國用戶(當然了,我們都是),參考這篇文章Using Flutter in China,設置一下中國的鏡像。 比如我用的是zsh,那我的設置如下: export PUB_HOSTED_URL=h ...
  • JS數據類型判斷 JavaScript 中常見數據類型有Number、String、Boolean、Object、Array、Json、Function、Date、RegExp、Error、undefined、Null等十幾種。ES6還有新增的數據類型有Symbol、Set、Map等。在實際應用中, ...
  • 迭代函數系統(Iterated Function System,IFS)可以用來創建分形圖案,它是分形理論的重要分支,也是分形圖形處理中最富生命力而且最具有廣闊應用前景的領域之一。這一工作最早可以追溯到Hutchinson於1981年對自相似集的研究。美國科學家M.F.Barnsley於1985年發 ...
  • 說起Web前端開發想必你一定不會陌生,因為現在的前端開發學習的培訓機構也是層出不窮。下麵濟南優就業IT培訓給大家總結出了未來Web前端開發的六大趨勢從中可以大致看出來Web前端未來的發展前景。 趨勢一:更加移動優先 響應式設計顯然是目前Web前端開發領域的主要趨勢之一,並且這一趨勢在未來還將持續一段 ...
  • 首先,為什麼說叫所謂呢? 因為在2007年之前Js給予我們typeof解析數據類型的一共有六種(一直有爭議,但是我們暫時就按typeof來算) 'function' 'Number' 'Object' 'boolean' 'String' 'undefined' 但當我們去 typeof Symbo ...
  • Nuxt 使用 create-nuxt-app 創建項目時,選擇使用 Element-UI 為預設組件庫,發現 Nuxt 沒有開啟 Element-UI 的按需引入配置,需要自行配置。 ...
  • display: none; DOM 結構:瀏覽器不會渲染 display 屬性為 none 的元素,不占據空間; 事件監聽:無法進行 DOM 事件監聽; 性能:動態改變此屬性時會引起重排,性能較差; 繼承:不會被子元素繼承,畢竟子類也不會被渲染; transition:transition 不支持 ...
一周排行
    -Advertisement-
    Play Games
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...