js實現(xiàn)抽獎功能
更新時間:2020年11月24日 13:29:55 作者:codeTcy
這篇文章主要為大家詳細(xì)介紹了js實現(xiàn)抽獎功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js實現(xiàn)抽獎功能的具體代碼,供大家參考,具體內(nèi)容如下
html部分:
<div id="title" class="title">開始抽獎啦</div> <div class="btns"> <span id="play">開始</span> <span id="stop">結(jié)束</span> </div>
css部分:
*{ margin: 0; padding: 0; } .title{ width: 400px; height:70px ; /*水平居中*/ margin: 0 auto; padding-top: 30px; text-align: center; font-size: 24px; color:#F00; } .btns{ width: 190px; height: 30px; margin: 0 auto; } .btns span{ display: block; float:left; width:80px; height:27px; line-height:27px; background:#036; border:1px solid #eee; border-radius:7px; margin-right:10px; color:#FFF; text-align:center; font-size:14px; font-family:"微軟雅黑"; cursor:pointer; }
Js部分:
var data=['Phone5','Ipad','筆記本','相機(jī)','打印機(jī)','謝謝參與','50元券']; var timer=null; window.function(){ var play=document.getElementById('play'); var stop=document.getElementById('stop'); play.playFun; stop.stopFun; } function playFun(){ var play=document.getElementById('play'); var title=document.getElementById('title'); clearInterval(timer); timer=setInterval(function(){ var random=Math.floor(Math.random()*data.length); title.innerHTML=data[random]; },50) play.style.background='#eee'; } function stopFun(){ var play=document.getElementById('play'); clearInterval(timer); play.style.background='#036'; }
想要學(xué)習(xí)更多關(guān)于抽獎功能的實現(xiàn),請參考此專題:抽獎功能
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
更改BootStrap popover的默認(rèn)樣式及popover簡單用法
這篇文章主要介紹了更改BootStrap popover的默認(rèn)樣式及popover簡單用法,需要的朋友可以參考下2018-09-09JSON創(chuàng)建鍵值對(key是中文或者數(shù)字)方式詳解
這篇文章主要介紹了JSON創(chuàng)建鍵值對(key是中文或者數(shù)字)方式詳解,需要的朋友可以參考下2017-08-08JavaScript下通過的XMLHttpRequest發(fā)送請求的代碼
JavaScript下通過的XMLHttpRequest發(fā)送請求的代碼,需要的朋友可以參考下。2011-06-06關(guān)于JavaScript中高階函數(shù)的魅力詳解
高階函數(shù):英文叫Higher-order function。JavaScript的函數(shù)其實都指向某個變量。下面這篇文章主要給大家介紹了關(guān)于JavaScript中高階函數(shù)的魅力,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-09-09學(xué)習(xí)JavaScript正則表達(dá)式
這篇文章主要介紹了JavaScript正則表達(dá)式,詳細(xì)深入的了解JavaScript正則表達(dá)式,從而更熟練掌握J(rèn)avaScript正則表達(dá)式,感興趣的小伙伴們可以參考一下2015-11-11