基于JavaScript實(shí)現(xiàn)隨機(jī)點(diǎn)名器
本文實(shí)例為大家分享了JavaScript實(shí)現(xiàn)隨機(jī)點(diǎn)名器的具體代碼,供大家參考,具體內(nèi)容如下
HTML代碼:
<body> <h1>點(diǎn)名啦</h1> <div id="did"> <input id="rollcall-id" type="button" value="隨機(jī)點(diǎn)名器"><br> <input id="action-id" type="submit" onclick="doClick()" value="開(kāi)始"> </div> </body>
CSS代碼:
<style> * { margin: 0px; padding: 0px; } body { background-color: rgb(255, 249, 249); } h1 { text-align: center; padding-top: 100px; color: rgba(250, 54, 129, 0.562); } #did { position: relative; width: 200px; margin: 60px auto; } #did input:first-child { width: 200px; height: 60px; background-color: rgba(250, 54, 129, 0.562); /* 不要邊框或設(shè)邊框?yàn)橥该?*/ border: none; border-radius: 20px; font-size: 25px; color: #fff; box-shadow: 0px 0px 3px 3px rgba(250, 54, 129, 0.158); /* 點(diǎn)擊時(shí)邊框消失 */ outline: 0; } #did input:nth-last-child(1) { width: 100px; height: 40px; margin: 40px 50px; background-color: rgba(250, 54, 129, 0.562); border: 1px solid transparent; background-color: rgba(255, 68, 177, 0.432); border-radius: 15px; box-shadow: 0px 0px 2px 2px rgba(250, 54, 129, 0.158); font-size: 17px; color: #333; outline: 0; transition: color 0.2s ease-out; transition: box-shadow 0.2s ease-out; } #did input:nth-last-child(1):hover { color: #fff; cursor: pointer; box-shadow: 0px 0px 4px 4px rgba(250, 54, 129, 0.158); } </style>
JavaScript代碼:
<script> var rollcall = document.getElementById("rollcall-id"); var action = document.getElementById("action-id"); var h1 = document.getElementsByTagName("h1"); //不能用name,用name只會(huì)取得一個(gè)字符 var allName = ["張柳菲", "高穎影", "趙溫言", "李穎", "鄧辰希", "莫若鄰", "秦橙", "吳筱宇", "趙希", "馬素瀅", "呂沁雅", "羅鴻哲", "夏素蕓", "謝焱之", "曹夢(mèng)朦", "李允書(shū)", "周楓橋", "孫浩", "江雁菁", "楊振凱", "林舒言", "錢妙妙", "郭景", "杜貝貝", "童閔然", "鐘小凌", "韓云韻", "白然之"]; //隨機(jī)產(chǎn)生一個(gè)名字 function stringRandom() { return parseInt(Math.random() * allName.length); } var time = null; var luckName; //開(kāi)始 function doStart() { if (time == null) { time = setInterval(function () { //獲取隨機(jī)點(diǎn)名的值 luckName = allName[stringRandom()]; rollcall.setAttribute("value", luckName); }, 100); } } //停止 function doStop() { if (time != null) { clearInterval(time); time = null; } } //點(diǎn)擊事件 function doClick() { if (action.value == "開(kāi)始") { //改變樣式 action.style.backgroundColor = "#cecece"; action.style.boxShadow = "0px 0px 2px 2px rgba(100, 100, 100, 0.4)"; action.value = "停止"; h1[0].innerHTML = "點(diǎn)名啦"; //開(kāi)始隨機(jī)點(diǎn)名 doStart(); } else if (action.value == "停止") { action.style.backgroundColor = "rgba(255, 68, 177, 0.432)"; action.style.boxShadow = "0px 0px 2px 2px rgba(250, 54, 129, 0.158)"; action.value = "開(kāi)始"; h1[0].innerHTML = "恭喜" + luckName + "同學(xué)獲得一次發(fā)言機(jī)會(huì)"; //停止 doStop(); } } </script>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- js實(shí)現(xiàn)簡(jiǎn)單的點(diǎn)名器隨機(jī)色實(shí)例代碼
- js實(shí)現(xiàn)簡(jiǎn)單的隨機(jī)點(diǎn)名器
- js實(shí)現(xiàn)隨機(jī)點(diǎn)名器精簡(jiǎn)版
- JS實(shí)現(xiàn)隨機(jī)點(diǎn)名器
- JavaScript實(shí)現(xiàn)隨機(jī)點(diǎn)名器
- JavaScript實(shí)現(xiàn)簡(jiǎn)單隨機(jī)點(diǎn)名器
- JavaScript實(shí)現(xiàn)隨機(jī)點(diǎn)名器實(shí)例詳解
- javascript實(shí)現(xiàn)的一個(gè)隨機(jī)點(diǎn)名功能
- 使用javascript做的一個(gè)隨機(jī)點(diǎn)名程序
- js實(shí)現(xiàn)隨機(jī)點(diǎn)名系統(tǒng)(實(shí)例講解)
相關(guān)文章
ESC之ESC.wsf可以實(shí)現(xiàn)javascript的代碼壓縮附使用方法
可以對(duì)javascript的大小進(jìn)行壓縮。使javascript的加載速度變快。2007-05-05js實(shí)現(xiàn)省級(jí)聯(lián)動(dòng)(數(shù)據(jù)結(jié)構(gòu)優(yōu)化)
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)省級(jí)聯(lián)動(dòng),數(shù)據(jù)結(jié)構(gòu)優(yōu)化,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-07-07JavaScript 對(duì)象模型 執(zhí)行模型
JavaScript 對(duì)象模型-執(zhí)行模型分析2009-12-12微信小程序開(kāi)發(fā)(二)圖片上傳+服務(wù)端接收詳解
本篇文章主要介紹了微信小程序開(kāi)發(fā)(二)圖片上傳+服務(wù)端接收,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-01-01基于Unit PNG Fix.js有時(shí)候在ie6下不正常的解決辦法
本篇文章是對(duì)Unit PNG Fix.js有時(shí)候在ie6下不正常的解決辦法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06