最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JS實現(xiàn)簡單九宮格抽獎

 更新時間:2022年06月28日 15:42:26   作者:ResidualBridge  
這篇文章主要為大家詳細(xì)介紹了JS實現(xiàn)簡單九宮格抽獎,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

用JavaScript寫一個九宮格的抽獎盤,供大家參考,具體內(nèi)容如下

點(diǎn)擊中間的塊,選中獎品的亮塊會在邊緣的8個塊循環(huán);

選中后,彈出選中的內(nèi)容;

代碼參考:

HTML文件:

<body>
<div class="box">
? ? <ul id="jiangPin">
? ? ? ? <li><a href="javascript:viod(0);" ><span>獎品 1</span></a></li>
? ? ? ? <li><a href="javascript:viod(0);" ><span>獎品 2</span></a></li>
? ? ? ? <li><a href="javascript:viod(0);" ><span>獎品 3</span></a></li>
? ? ? ? <li><a href="javascript:viod(0);" ><span>獎品 4</span></a></li>
? ? ? ? <li><a href="javascript:viod(0);" ><span>獎品 5</span></a></li>
? ? ? ? <li><a href="javascript:viod(0);" ><span>獎品 6</span></a></li>
? ? ? ? <li><a href="javascript:viod(0);" ><span>獎品 7</span></a></li>
? ? ? ? <li><a href="javascript:viod(0);" ><span>獎品 8</span></a></li>
? ? </ul>
? ? <button type="button" class="btn" id="beginBtn">點(diǎn)擊開始</button>
? ? <div class="tishi" id="tishi">
? ? ? ? <span>恭喜您獲得:</span>
? ? ? ? <p></p>
? ? ? ? <button>確定</button>
? ? </div>
</div>
</body>

通過position定位來固定獎盤各個板塊的位置,將有獎品的8個塊分散在九宮格的邊緣,開始按鈕在九宮格正中間,將彈出的提示框放于整個獎盤的上層顯示,初始將其隱藏。

CSS文件:

.box{
? ? width: 450px;
? ? height: 450px;
? ? background-color: #9a6e3a;
? ? border: 2px solid #990055;
? ? position: relative;
? ? z-index: 10;
}
.box>ul>li{
? ? position: absolute;
? ? width: 148px;
? ? height: 148px;
? ? border: 1px #222222 solid;
? ? background-color: #ad889d;
}
.box>ul>li>a{
? ? display: block;
? ? color: #fff;
? ? font-size: 30px;
? ? text-align: center;
? ? line-height: 148px;
}
/* 開始按鈕 */
.btn{
? ? position: absolute;
? ? top: 150px;
? ? left: 150px;
? ? width: 150px;
? ? height: 150px;
? ? border: 1px #222222 solid;
? ? background-color: #7d53c7;
? ? outline: none;
? ? cursor: pointer;
? ? color: #fff;
? ? font-size: 25px;
? ? transition: all 0.5s;
? ? z-index: 20;
}
.btn:hover{
? ? background-color: #df04ff;
? ? font-size: 30px;
}
.btn:active{
? ? background-color: #7d53c7;
}
.box>ul>li.on{
? ? background-color: #f00;
}
/* 開始按鈕 end */

/* 獎品定位 */
.box>ul>li:nth-child(1){
? ? top: 0;
? ? left: 0;
}
.box>ul>li:nth-child(2){
? ? top: 0;
? ? left: 150px;
}
.box>ul>li:nth-child(3){
? ? top: 0;
? ? left: 300px;
}
.box>ul>li:nth-child(4){
? ? top: 150px;
? ? left: 300px;
}
.box>ul>li:nth-child(5){
? ? top: 300px;
? ? left: 300px;
}
.box>ul>li:nth-child(6){
? ? top: 300px;
? ? left: 150px;
}
.box>ul>li:nth-child(7){
? ? top: 300px;
? ? left: 0;
}
.box>ul>li:nth-child(8){
? ? top: 150px;
? ? left: 0;
}
/* 獎品定位 end */

/* 提示框 */
.tishi{
? ? width: 300px;
? ? height: 146px;
? ? border: 2px #990055 solid;
? ? background: #92EC1F;
? ? border-radius: 20px;
? ? position: absolute;
? ? left: 50%;
? ? top: 50%;
? ? margin-top: -75px;
? ? margin-left: -150px;
? ? z-index: 30;
? ? text-align: center;
? ? font-size: 25px;
? ? font-weight: bold;
? ? display: none;
? ? animation: tishiAni 0.5s both;
? ? transition: all 0.5s;
}
.tishi>p{
? ? color: red;
? ? font-size: 28px;
? ? margin-top: 20px;
}
.tishi>button{
? ? width: 60px;
? ? height: 30px;
? ? border:none;
? ? outline: none;
? ? cursor: pointer;
? ? position: absolute;
? ? right: 30px;
? ? bottom: 20px;
}
@keyframes tishiAni {
? ? 0%{
? ? ? ? opacity: 0;
? ? }
? ? 100%{
? ? ? ? opacity: 1;
? ? }
}
/* 提示框 end */

通過計時器來實現(xiàn)獎品亮塊的循環(huán)

JavaScript文件:

{
? ? let jiangPinChi = [
? ? ? ? "獎品1",
? ? ? ? "獎品2",
? ? ? ? "獎品3",
? ? ? ? "獎品4",
? ? ? ? "獎品5",
? ? ? ? "獎品6",
? ? ? ? "獎品7",
? ? ? ? "獎品8",
? ? ];

? ? let index = 0;
? ? let times = Math.round( Math.random()*20 ) +20 ;
? ? let jiangPin = document.getElementById("jiangPin");
? ? let beginBtn = document.getElementById("beginBtn");
? ? let tishi = document.getElementById("tishi");
? ? let cont = tishi.children;
? ? let jPLi = jiangPin.children;

? ? let liBro = function (tag) {
? ? ? ? let fat = tag.parentNode;
? ? ? ? let tagLi = fat.children;
? ? ? ? let othLis = [];
? ? ? ? for (let jPLi of tagLi) {
? ? ? ? ? ? if (jPLi === tag) {
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? othLis.push(jPLi);
? ? ? ? }
? ? ? ? return othLis;
? ? };

? ? let showing = function( index ) {
? ? ? ? let othLis = liBro( jPLi[index] );
? ? ? ? for( let i = 0; i<=othLis.length-1 ; i++ ){
? ? ? ? ? ? othLis[i].classList.remove("on");
? ? ? ? }
? ? ? ? // othLis.forEach(function( value,i ){
? ? ? ? // ? ? value.classList.remove("on");
? ? ? ? // });
? ? ? ? jPLi[index].classList.add("on");
? ? };

? ? let changeFun = function( event ){
? ? ? ? let myset = setInterval(function(){
? ? ? ? ? ? index++;
? ? ? ? ? ? times--;
? ? ? ? ? ? if( index > jPLi.length-1 ){
? ? ? ? ? ? ? ? index = 0;
? ? ? ? ? ? }
? ? ? ? ? ? showing( index );
? ? ? ? ? ? if( times <= 0 ){
? ? ? ? ? ? ? ? clearInterval(myset);
? ? ? ? ? ? ? ? times = Math.round( Math.random()*20 ) +20;
? ? ? ? ? ? ? ? tishi.style.display = "block";
? ? ? ? ? ? ? ? cont[1].innerHTML = jiangPinChi[index];
? ? ? ? ? ? }
? ? ? ? },100);
? ? };
? ? beginBtn.addEventListener("click",changeFun);
? ? cont[2].addEventListener("click",function( event ){
? ? ? ? tishi.style.display = "none";
? ? });
}

當(dāng)然,這個可以擴(kuò)展成更多的類型,實現(xiàn)不止九宮格的獎盤抽獎模式。

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

相關(guān)文章

  • checkbox選中與未選中判斷示例

    checkbox選中與未選中判斷示例

    本節(jié)主要介紹了checkbox選中與未選中的判斷方法,需要的朋友可以參考下
    2014-08-08
  • js前端加載超大圖片(100M以上)實現(xiàn)秒開的最佳解決方案

    js前端加載超大圖片(100M以上)實現(xiàn)秒開的最佳解決方案

    前端加載超大圖片時,一般可以采取圖片壓縮,圖片分割,預(yù)加載等措施,而對于幾百M(fèi)或上G的大圖而言,不管對圖片進(jìn)行怎么優(yōu)化或加速處理,要實現(xiàn)秒開也是不太可能的事情,所以本文小編將給大家介紹如何對大圖進(jìn)行分割,在前端進(jìn)行拼接實現(xiàn)秒開,需要的朋友可以參考下
    2023-10-10
  • 微信小程序獲取地理位置及經(jīng)緯度授權(quán)代碼實例

    微信小程序獲取地理位置及經(jīng)緯度授權(quán)代碼實例

    這篇文章主要介紹了微信小程序獲取地理位置及經(jīng)緯度授權(quán)代碼實例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-09-09
  • JavaScript鼠標(biāo)拖拽事件詳解

    JavaScript鼠標(biāo)拖拽事件詳解

    這篇文章主要為大家詳細(xì)介紹了JavaScript鼠標(biāo)拖拽事件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • 基于JS實現(xiàn)帶動畫效果的流程進(jìn)度條

    基于JS實現(xiàn)帶動畫效果的流程進(jìn)度條

    當(dāng)在使用流程的時候,比如有一個審核流程,有三個階段:開始,審核中,審核成功。當(dāng)在不同的階段,做相應(yīng)的進(jìn)度顯示,當(dāng)顯示時,是以動畫的形式顯示的。下面通過代碼給大家介紹JS實現(xiàn)帶動畫效果的流程進(jìn)度條,感興趣的朋友一起看看吧
    2018-06-06
  • js實現(xiàn)圖片輪播效果

    js實現(xiàn)圖片輪播效果

    這篇文章主要介紹了js實現(xiàn)圖片輪播效果的相關(guān)資料,需要的朋友可以參考下
    2015-12-12
  • 前端點(diǎn)擊預(yù)覽圖片Viewer.js使用方法(簡單的操作)

    前端點(diǎn)擊預(yù)覽圖片Viewer.js使用方法(簡單的操作)

    這篇文章主要介紹了前端點(diǎn)擊預(yù)覽圖片Viewer.js使用的相關(guān)資料,Viewer.js是一款強(qiáng)大的圖片查看器,支持移動設(shè)備觸摸事件、響應(yīng)式、放大/縮小、旋轉(zhuǎn)、翻轉(zhuǎn)、移動、鍵盤操作、全屏幻燈片模式、縮略圖和標(biāo)題顯示等功能,需要的朋友可以參考下
    2025-01-01
  • js點(diǎn)擊按鈕實現(xiàn)水波紋效果代碼(CSS3和Canves)

    js點(diǎn)擊按鈕實現(xiàn)水波紋效果代碼(CSS3和Canves)

    這篇文章主要為大家詳細(xì)介紹了點(diǎn)擊按鈕實現(xiàn)水波紋效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • BootStrap表單驗證實例代碼

    BootStrap表單驗證實例代碼

    這篇文章主要介紹了bootstrap表單驗證的實例代碼,代碼中包括引入的js文件,具體實現(xiàn)方法,大家參考本文
    2017-01-01
  • Javascript中JSON數(shù)據(jù)分組優(yōu)化實踐及JS操作JSON總結(jié)

    Javascript中JSON數(shù)據(jù)分組優(yōu)化實踐及JS操作JSON總結(jié)

    這篇文章主要介紹了Javascript中JSON數(shù)據(jù)分組優(yōu)化實踐,文中還對JS操作JSON的要領(lǐng)做了總結(jié),需要的朋友可以參考下
    2017-12-12

最新評論

茶陵县| 佛教| 论坛| 桓仁| 沈阳市| 湖南省| 佛冈县| 康马县| 东乌| 广河县| 盱眙县| 福鼎市| 婺源县| 平湖市| 新竹县| 得荣县| 北碚区| 佛山市| 西丰县| 东丰县| 云阳县| 嘉兴市| 定日县| 昌都县| 铜陵市| 金湖县| 正安县| 义马市| 华阴市| 汕头市| 论坛| 东山县| 康定县| 清新县| 横山县| 新津县| 乌恰县| 浮山县| 佛山市| 洪雅县| 合水县|