欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

原生js實(shí)現(xiàn)簡(jiǎn)易抽獎(jiǎng)系統(tǒng)

 更新時(shí)間:2022年03月09日 11:31:17   作者:小鑫a  
這篇文章主要為大家詳細(xì)介紹了原生js實(shí)現(xiàn)簡(jiǎn)易抽獎(jiǎng)系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js實(shí)現(xiàn)簡(jiǎn)易抽獎(jiǎng)系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

效果圖

原理:

其實(shí)這里的原理就是通過(guò)按鈕的狀態(tài)是開(kāi)始抽獎(jiǎng)還是停止 如果i=ture 那就觸發(fā)定時(shí)器 每50毫秒更換一次中獎(jiǎng)的內(nèi)容。如果i=false,那就清除定時(shí)器,顯示最后的抽獎(jiǎng)結(jié)果

下面我給大家畫了個(gè)更直觀的圖

HTML結(jié)構(gòu)與樣式

<!doctype html>
<html lang="en">
<head>
?? ?<meta charset="UTF-8">
?? ?<title>Document</title>
?? ?<style>
?? ??? ?* {
?? ??? ??? ?margin: 0;
?? ??? ??? ?padding: 0;
?? ??? ?}

?? ??? ?h2 {
?? ??? ??? ?font-weight: normal;
?? ??? ?}

?? ??? ?.box {
?? ??? ??? ?width: 450px;
?? ??? ??? ?height: auto;
?? ??? ??? ?background: #fff;
?? ??? ??? ?border-radius: 3px;
?? ??? ??? ?margin: 50px auto;
?? ??? ??? ?padding-bottom: 1em;
?? ??? ??? ?box-shadow: 0 10px 10px 0 rgba(0, 0, 0, 0.2), 0 5px 15px 0 rgba(0, 0, 0, 0.19);
?? ??? ?}

?? ??? ?.header {
?? ??? ??? ?width: 100%;
?? ??? ??? ?height: auto;
?? ??? ??? ?padding: 0.5em 0.8em;
?? ??? ??? ?border-bottom: 1px solid #ccc;
?? ??? ??? ?box-sizing: border-box;
?? ??? ?}

?? ??? ?.body {
?? ??? ??? ?width: 100%;
?? ??? ??? ?height: auto;
?? ??? ??? ?text-align: center;
?? ??? ?}

?? ??? ?.body:after {
?? ??? ??? ?content: "";
?? ??? ??? ?display: block;
?? ??? ??? ?clear: both;
?? ??? ?}

?? ??? ?.body > div {
?? ??? ??? ?width: 180px;
?? ??? ??? ?margin: 0 auto;
?? ??? ?}

?? ??? ?.body > div > span {
?? ??? ??? ?padding-top: 1em;
?? ??? ??? ?float: left;
?? ??? ?}

?? ??? ?#tip {
?? ??? ??? ?display: none;
?? ??? ?}

?? ??? ?.footer {
?? ??? ??? ?width: 180px;
?? ??? ??? ?height: 30px;
?? ??? ??? ?background: #2ab8ff;
?? ??? ??? ?line-height: 30px;
?? ??? ??? ?text-align: center;
?? ??? ??? ?margin: 1em auto;
?? ??? ??? ?color: #ccc;
?? ??? ??? ?border: 1px solid #2193cc;
?? ??? ??? ?border-radius: 3px;
?? ??? ??? ?cursor: pointer;
?? ??? ?}

?? ??? ?.footer:hover {
?? ??? ??? ?background: #4ec1fb;
?? ??? ?}

?? ?</style>
</head>
<body>
?? ?<div class="box">
?? ??? ?<div class="header">
?? ??? ??? ?<h2>簡(jiǎn)易抽獎(jiǎng)系統(tǒng)</h2>
?? ??? ?</div>
?? ??? ?<div class="body">
?? ??? ??? ?<div>
?? ??? ??? ??? ?<span id="tip">恭喜你!獲得:</span>
?? ??? ??? ??? ?<span id="put"></span>
?? ??? ??? ?</div>
?? ??? ?</div>
?? ??? ?<div class="footer">
?? ??? ??? ?點(diǎn)擊抽獎(jiǎng)
?? ??? ?</div>
</div>

js代碼

<script>
?? ??? ?/* 獲取按鈕 */
?? ??? ?var btn = document.querySelector('.footer');
?? ??? ?/* 獲取提示的標(biāo)簽 */
?? ??? ?var tip = document.querySelector('#tip');
?? ??? ?/* 獲取要輸出的標(biāo)簽 */
?? ??? ?var put = document.querySelector('#put');
?? ??? ?/* 定義中獎(jiǎng)的項(xiàng)目 */
?? ??? ?var gift = ['QQ會(huì)員','黃鉆','綠鉆','黑鉆','紫鉆','紅鉆','藍(lán)鉆','鉆皇'];
?? ??? ?/* 定義i==true 用于判斷 */
?? ??? ?var i = true;
?? ??? ?/* 定義定時(shí)器 */
?? ??? ?var Timer;
?? ??? ?var n = 0;

?? ??? ?btn.onclick=function() {
?? ??? ??? ?if (i == true) {
?? ??? ??? ??? ?btn.style.background = '#f1516c';
?? ??? ??? ??? ?btn.style.borderColor = '#db2745';
?? ??? ??? ??? ?tip.style.display = 'block';
?? ??? ??? ??? ?Timer = setInterval(function() {
?? ??? ??? ??? ??? ?n++;
?? ??? ??? ??? ??? ?if (n == gift.length) {
?? ??? ??? ??? ??? ??? ?n = 0;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?put.innerHTML = gift[n];
?? ??? ??? ??? ?},50)
?? ??? ??? ??? ?btn.innerHTML = '停止';
?? ??? ??? ??? ?i = false;
?? ??? ??? ?}else {
?? ??? ??? ??? ?btn.style.background = '#2ab8ff';
?? ??? ??? ??? ?btn.style.borderColor = '#2193cc';
?? ??? ??? ??? ?clearInterval(Timer);
?? ??? ??? ??? ?btn.innerHTML = '開(kāi)始抽獎(jiǎng)';
?? ??? ??? ??? ?i = true;
?? ??? ??? ?}
?? ??? ?}
</script>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論