美文网首页
js之简单的转盘抽奖

js之简单的转盘抽奖

作者: 弦生_a3a3 | 来源:发表于2020-07-09 10:05 被阅读0次

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>大转盘</title>

</head>

<style>

*{

    margin: 0;

    padding: 0;

    list-style: none;

}

ul{

    display: block;

    width: 600px;

    height: 600px;

    margin: 100px auto;

    display: flex;

    flex-wrap: wrap;

    justify-content: start;

}

ul>li{

    width: 200px;

    height: 200px;

    background-color: lightblue;

    color: #fff;

    font-size: 24px;

    display: flex;

    justify-content: space-around;

    align-items: center;

    border: 1px solid #fff;

    box-sizing: border-box;

}

ul>li.active{

    background-color: orangered;

}

button{

    border: none;

    position: relative;

    padding: 10px 18px;

    cursor: pointer;

    outline: none;

}

button::after{

    content: '';

    width: 0;

    height: 1px;

    position: absolute;

    background-color: rgb(53, 178, 228);

    left: 0;

    transition: all .3s linear;

    top: 0 ;

}

button::before{

    content: '';

    width: 0;

    height: 1px;

    position: absolute;

    background-color: rgb(50, 192, 248);

    right: 0;

    transition: all .3s linear;

    bottom: 0 ;

}

button:hover:after,button:hover:before{

width: 100%;

}

li:nth-child(5){

    border-radius: 50%;

}

</style>

<body>

<ul>

    <li class="active">100</li>

    <li>200 </li>

    <li>300</li>

    <li>400</li>

    <li>

        <button class="star" onclick="stars()">开始</button>

        <button class="end" onclick="over()">结束</button>

    </li>

    <li>500</li>

    <li>600</li>

    <li>700</li>

    <li>800</li>

</ul>

    <script>

        let li=document.querySelectorAll('li');

        let star=document.querySelector('.star'),end=document.querySelector('.end');

        let arr=[0,1,2,5,8,7,6,3];

        let timer,num=0;

        function auto(){

            for(let i=0;i<li.length;i++){

                li[i].classList.remove('active')

            }

            li[arr[num]].classList.add('active');

            num++;

            if(num>=arr.length){

                num=0;

            }

        }

        function stars(){

            timer= setInterval(auto,20)

            star.setAttribute('disabled',true)

        }

        function over(){

            clearInterval(timer)

            star.removeAttribute('disabled')

        }

    </script>

</body>

</html>

相关文章

  • js之简单的转盘抽奖

    大转盘 *{ margin:0; padding:0; list-style:no...

  • JS实现抽奖转盘

    超级简单的原理:点击转盘指针后随机得到一个数(每个数字对应一个奖项),并确定每个奖项在轮盘上的大概角度,然后调用 ...

  • css 如何“画”一个抽奖转盘

    主要描述的是如何运用 css 绘制一个抽奖转盘,并运用原生 js 实现转盘抽奖效果。 先来张效果图: 布局 一般来...

  • 抽奖转盘的简单思路

    抽奖大概是有个旋转的转盘,然后点击开始后,就可以开始转动转盘,同时也在跟后端发送验证请求,然后得到请求之后,开始不...

  • Scratch—转盘抽奖

    【知识延伸】 传统抽奖分为抽奖盒抽取、转盘抽奖等 【要求】 今天我们按照平时转盘抽奖、利用Scratch做一个转盘...

  • php实现刮刮卡大转盘抽奖概率

    php实现刮刮卡大转盘抽奖概率 本文实例为大家分享了php中奖概率算法,可用于刮刮卡,大转盘等抽奖算法,用法很简单...

  • 微信小程序幸运大转盘制作教程

    幸运大转盘抽奖方式是我见过最常用的抽奖方式了,这种方式简单,直接,让人看着兴奋。那么,幸运大转盘微信小程序怎么制作...

  • Android超简单实现九宫格抽奖

    目录 前言 如果有小伙伴想实现转盘抽奖效果的话请看我的另一篇文章《Android超简单实现自定义抽奖转盘效果》 效...

  • 抽奖转盘

    最近在写书上,老是看到别人抽一万钻的,我非常羡慕,就是我就试了试。 第一次我抽到的是解书钻二,我心想怎么这么倒霉,...

  • 抽奖转盘

    1.组件实现 2. 组件使用

网友评论

      本文标题:js之简单的转盘抽奖

      本文链接:https://www.haomeiwen.com/subject/hmljcktx.html