首页 > 其他分享 >抽奖

抽奖

时间:2022-10-10 17:34:59浏览次数:42  
标签:抽奖 span list length slow let names

  1 <!DOCTYPE html>
  2 <html lang="en">
  3 
  4 <head>
  5     <meta charset="UTF-8">
  6     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8     <title>Document</title>
  9     <style>
 10         * {
 11             margin: 0;
 12             padding: 0;
 13         }
 14 
 15         body {
 16             width: 100%;
 17             height: 100vh;
 18             display: flex;
 19             align-items: center;
 20             justify-content: center;
 21             background: #333;
 22             overflow: hidden;
 23         }
 24 
 25         .list {
 26             width: 400px;
 27             height: 400px;
 28             border: 1px solid #fff;
 29             border-radius: 50%;
 30             display: flex;
 31             align-items: center;
 32             justify-content: center;
 33             position: relative;
 34         }
 35         /* 红色箭头 */
 36         .list::after {
 37             content: '';
 38             position: absolute;
 39             width: 0;
 40             height: 0;
 41             border-width: 6px;
 42             border-style: solid;
 43             border-color: transparent transparent transparent red;
 44             right: 0;
 45         }
 46 
 47         .list::before {
 48             content: attr(data);
 49             position: absolute;
 50             color: #1e90ff;
 51             font-size: 64px;
 52         }
 53 
 54         .list span {
 55             color: #fff;
 56             position: absolute;
 57             width: calc(100% + 120px);
 58             height: 20px;
 59             text-align: right;
 60             transition: 0.01s linear;
 61             user-select: none;
 62         }
 63     </style>
 64 </head>
 65 
 66 <body>
 67     <div class="list"></div>
 68 </body>
 69 
 70 </html>
 71 <script>
 72     class Lottery {
 73         constructor() {
 74             this.list = document.querySelector('.list');
 75             this.randomSurnam = ["赵", "钱", "孙", "李", "周", "吴", "郑", "王", "冯", "陈", "褚", "卫", "蒋", "沈", "韩", "杨"];
 76             this.randomName = ["泽", "桐", "梓", "一", "宁", "梅", "生", "平", "明", "涵", "韵", "宸", "坤", "华", "星", "家"];
 77             this.names = [];
 78             this.run = true;
 79             this.deg = 0;
 80             this.slow = 0;
 81             this.init()
 82         }
 83         init() {
 84             for (let i = 0; i < 40; i++) {
 85                 this.names.push(
 86                     this.randomSurnam[Math.random() * this.randomSurnam.length | 0] +
 87                     this.randomName[Math.random() * this.randomName.length | 0] +
 88                     this.randomName[Math.random() * this.randomName.length | 0]
 89                 )
 90             }
 91 
 92             for (let key in this.names) {
 93                 let span = document.createElement('span');
 94                 span.innerText = this.names[key];
 95                 this.list.appendChild(span);
 96             }
 97             this.event()
 98         }
 99         draw() {
100             const spans = this.list.children;
101             for (let i = 0; i < spans.length; i++) {
102                 let span = spans[i];
103                 span.style.transform = `rotate(${i / this.names.length * 360 + this.deg}deg)`;
104                 span.style.color = '#fff';
105             }
106             const now = ((360 - this.deg) / 360 * this.names.length | 0) % this.names.length;
107             this.list.setAttribute('data', this.names[now]);
108             spans[now].style.color = 'red';
109             if (this.run) {
110                 this.slow = 1;
111             } else {
112                 this.slow = this.slow * 0.995;
113             }
114             this.deg -= this.slow;
115         }
116         animate() {
117             setInterval(() => this.draw(), 10);
118         }
119         event() {
120             document.addEventListener('keyup', (e) => {
121                 if (e.code === 'Space') {
122                     this.run = !this.run;
123                 }
124             });
125         }
126     }
127     new Lottery().animate()
128 </script>

 

标签:抽奖,span,list,length,slow,let,names
From: https://www.cnblogs.com/sheep-fu/p/16776517.html

相关文章

  • java----模拟幸运抽奖小案例
    模拟幸运抽奖案例:功能:用户注册:注册后随机生成4位数的卡号登录:三次机会,失败一次扣一次机会,机会为0返回主操作幸运抽奖:注册后生成的4位数卡号与随机生成的5个4位数卡号对......
  • 年会没中奖,老板买了一个抽奖程序
    前言昨天参加了公司年会,显然我啥奖项都没中,什么“优秀员工”都跟我们前端工程师无关,不然我不会在这里写文了,等等,这里为什么要用“我们”,[疑问.jpg],前端工程师应该是评不到“......
  • 幸运大抽奖
    幸运大抽奖#include<stdio.h>#include<time.h>#include<stdlib.h>#include<windows.h>intmain(){srand((unsignedint)time(NULL));//把时间作为我们的随机数......
  • 基于股指的美团抽奖规则
    美团抽奖规则:每日收盘时的上证指数×每日收盘时的深证成指×10000=12位数。(指数以证交所公布数字为准);将此12位数的数字倒序排列后(如首位是0,则直接抹去),再除以前一日2......
  • JQuery抽奖案例实现
    JQuery抽奖案例实现分析:给开始按钮绑定单机事件定义循环定时器切换小相框的src属性定义一个数组,存放图片资源......
  • JQuery案例_广告显示和隐藏&JQuery案例_抽奖
    JQuery案例_广告显示和隐藏需求:当页面加载完,3秒后自动显示广告广告显示5秒后,自动消失分析:使用定时器来完成。setTimeout(执行一次定时器)分析发现JQuery的显示......
  • JQuery广告显示和隐藏案例和JQuery抽奖案例
    JQuery广告显示和隐藏案例需求:1.当页面加载完,3秒后。自动显示广告2.广告显示5秒后,自动消失。分析:1.使用定时器来完成。setTimeout(执行一次定时器)2.分析......
  • 1069 微博转发抽奖——20分
    小明PAT考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔N个人就发出一个红包。请你编写程序帮助他确定中奖名单。输入格式:输入第一行给出三个正整数M......