欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

JS如何實(shí)現(xiàn)點(diǎn)星星消除小游戲

這篇文章給大家分享的是有關(guān)JS如何實(shí)現(xiàn)點(diǎn)星星消除小游戲的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

成都創(chuàng)新互聯(lián)公司專注于玄武網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供玄武營銷型網(wǎng)站建設(shè),玄武網(wǎng)站制作、玄武網(wǎng)頁設(shè)計(jì)、玄武網(wǎng)站官網(wǎng)定制、微信平臺(tái)小程序開發(fā)服務(wù),打造玄武網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供玄武網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

具體內(nèi)容如下

步驟及游戲功能分析:

1.網(wǎng)頁上的隨機(jī)出現(xiàn)小星星;

2.點(diǎn)擊小星星,小星星消失;

    綁定一個(gè)onclick事件:
    對象.事件 = 事件處理函數(shù);
    注意:要想刪除某個(gè)節(jié)點(diǎn),必須找到它的父節(jié)點(diǎn)
    注意:在綁定事件中this可以直接使用

3.添加功能開始游戲

4.添加功能暫停游戲

5.游戲進(jìn)度條功能

<style type="text/css">
 #d2{
 width: 100px;
 height: 20px;
 border: 1px solid red;
 display: inline-block;
 }
 #d3{
 display: inline-block;
 background: yellow;
 height: 20px;
 }
</style>
<script type="text/javascript">
 //window.onload = init;
 
 var countstar = 0;//控制星星個(gè)數(shù)變量
 var timerStar;//生成星星定時(shí)器
 var timerGameTime
 var t = 0;//記錄時(shí)間變量
 //開始游戲的函數(shù)
 function startGame(){
 window.clearInterval(timerStar);
 window.clearInterval(timerGameTime);
 timerStar = window.setInterval("star()",500);
 timerGameTime = window.setInterval("time()",1000); //記錄游戲時(shí)間
 }
 
 //創(chuàng)建星星的函數(shù)
 function star(){
 var obj = document.createElement("img");
 obj.src = "images/star.png";
 obj.width = Math.floor(Math.random()*60+20);
 obj.style.position = "absolute";
 obj.style.left = Math.floor(Math.random()*1700+100)+"px";
 obj.style.top = Math.floor(Math.random()*500+30)+"px";
 document.body.appendChild(obj);
 countstar++;
 var sp = document.getElementById("d3");
 sp.style.width = countstar*10+"px";
 
 if (countstar > 10) {
  alert("游戲結(jié)束");
  window.clearInterval(timerStar);
  location.reload();
 }
 obj.onclick = removeStar;
 }
 
 //點(diǎn)擊刪除星星的函數(shù)
 function removeStar(){
 this.parentNode.removeChild(this);
 countstar --;
 var sp = document.getElementById("d3");
 sp.style.width = countstar*10+"px";
 }
 
 //點(diǎn)擊暫停游戲的函數(shù)
 function pauseGame(){
 alert("游戲已暫停,點(diǎn)擊確定繼續(xù)游戲。");
 }
 
 //記錄游戲時(shí)間的函數(shù)
 function time(){
 t++
 var obj = document.getElementById("d1");
 obj.innerHTML= "游戲進(jìn)行了"+t+"秒";
 }
</script>
 
<body>
  <input type="button" value="開始游戲" οnclick="startGame()" name="">
  <input type="button" value="暫停游戲" οnclick="pauseGame()" name="">
  <span id="d1">游戲進(jìn)行了0秒</span>
  <span id="d2"><span id="d3"></span></span>
</body>

游戲效果:

JS如何實(shí)現(xiàn)點(diǎn)星星消除小游戲

感謝各位的閱讀!關(guān)于“JS如何實(shí)現(xiàn)點(diǎn)星星消除小游戲”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

當(dāng)前題目:JS如何實(shí)現(xiàn)點(diǎn)星星消除小游戲
文章源于:http://chinadenli.net/article12/gghggc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)App開發(fā)網(wǎng)站設(shè)計(jì)電子商務(wù)網(wǎng)站改版虛擬主機(jī)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作