javascript跑馬燈抽獎(jiǎng)實(shí)例講解
本文實(shí)例講解了javascript跑馬燈抽獎(jiǎng)特效,特別適合用于抽獎(jiǎng)活動(dòng),分享給大家供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>抽獎(jiǎng)游戲</title> <style> #box{ width:720px; margin:0 auto; margin-top:20px; box-shadow:0px 0px 2px #333; } .pic{ width:200px; height:200px; float:left; line-height:200px; margin:10px; border:5px #fff solid; color:blue; font-size: 35px; text-align: center; } .anniu{ width:200px; height:200px; float:left; margin:10px; } #drawBtn{ color:red; font-size:30px; width:200px; height:200px; box-shadow:0px 0px 2px #333; font-weight: bold; } </style> <script> window.onload=init; var setting={ count:0, total:24, delay:20, picIndex:[0,1,2,4,7,6,5,3] } function init(){ document.getElementById("drawBtn").onclick=function(){ setting.count=0; setting.delay=20; this.disable=true;//禁用按鈕 var drawBtn=this; //獲取所有圖片的div var allDivs=document.getElementsByClassName("pic"); //獲得一個(gè)隨機(jī)整數(shù),代表中獎(jiǎng)的那個(gè)位置,3*8+(0-7) setting.total+=Math.floor(Math.random()*allDivs.length); //設(shè)置定時(shí)器,依次修改每個(gè)div邊框的顏色. setTimeout(function show(){ //重置上一個(gè)邊框的顏色 for (var i=0;i<allDivs.length;i++){ allDivs[i].style.borderColor="#fff"; allDivs[i].style.opacity=0.7; } //找到要修改的那個(gè)邊框的顏色設(shè)置 var currentPic=allDivs[setting.picIndex[setting.count%8]]; currentPic.style.borderColor="red"; currentPic.style.opacity=1.0; setting.count++; setting.delay+=2*setting.count; if(setting.count>setting.total){ alert("您中獎(jiǎng)了,哈哈"); drawBtn.disable=false; return; } setTimeout(show,setting.delay); },setting.delay); } } </script> </head> <body> <div id="box"> <div class="pic">1</div> <div class="pic">2</div> <div class="pic">3</div> <div class="pic">4</div> <div class="anniu"><input type="button" value="我要抽獎(jiǎng)" id="drawBtn"/></div> <div class="pic">5</div> <div class="pic">6</div> <div class="pic">7</div> <div class="pic">8</div> </div> </body> </html>
想要學(xué)習(xí)更多關(guān)于抽獎(jiǎng)功能的實(shí)現(xiàn),請(qǐng)參考此專題:抽獎(jiǎng)功能
以上就是本文的詳細(xì)內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
相關(guān)文章
大轉(zhuǎn)盤抽獎(jiǎng)小程序版 轉(zhuǎn)盤抽獎(jiǎng)網(wǎng)頁(yè)版
這篇文章主要為大家詳細(xì)介紹了大轉(zhuǎn)盤抽獎(jiǎng)小程序版和網(wǎng)頁(yè)版,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01小程序通過小程序云實(shí)現(xiàn)微信支付功能實(shí)例
本文主要介紹了小程序通過小程序云實(shí)現(xiàn)微信支付功能實(shí)例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-07-07等待指定時(shí)間后自動(dòng)跳轉(zhuǎn)或關(guān)閉當(dāng)前頁(yè)面的js代碼
本文為大家詳細(xì)介紹下如何通過js實(shí)現(xiàn)等待指定時(shí)間后自動(dòng)跳轉(zhuǎn)或關(guān)閉當(dāng)前頁(yè)面的腳步代碼,感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助2013-07-07setinterval()與clearInterval()JS函數(shù)的調(diào)用方法
這篇文章主要介紹了setinterval()與clearInterval()JS函數(shù)的調(diào)用方法,實(shí)例分析了setinterval()與clearInterval()的語(yǔ)法結(jié)構(gòu)及使用技巧,需要的朋友可以參考下2015-01-01TypeScript?類型斷言的幾種實(shí)現(xiàn)
本文主要介紹了TypeScript?類型斷言的實(shí)現(xiàn),有使用關(guān)鍵字as和標(biāo)簽<>兩種方式,具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01JavaScript實(shí)現(xiàn)經(jīng)緯度轉(zhuǎn)換成地址功能
這篇文章主要介紹了JavaScript實(shí)現(xiàn)經(jīng)緯度轉(zhuǎn)換成地址,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03