js實(shí)現(xiàn)抽獎功能
本文實(shí)例為大家分享了js實(shí)現(xiàn)抽獎功能的具體代碼,供大家參考,具體內(nèi)容如下
html部分:
<div 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)于抽獎功能的實(shí)現(xiàn),請參考此專題:抽獎功能
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python 如何在 Matplotlib 中繪制垂直線2. bootstrap select2 動態(tài)從后臺Ajax動態(tài)獲取數(shù)據(jù)的代碼3. ASP常用日期格式化函數(shù) FormatDate()4. python中@contextmanager實(shí)例用法5. html中的form不提交(排除)某些input 原創(chuàng)6. CSS3中Transition屬性詳解以及示例分享7. js select支持手動輸入功能實(shí)現(xiàn)代碼8. 如何通過python實(shí)現(xiàn)IOU計算代碼實(shí)例9. 開發(fā)效率翻倍的Web API使用技巧10. vue使用moment如何將時間戳轉(zhuǎn)為標(biāo)準(zhǔn)日期時間格式
