html:

<div class="line_item" :class="index == 1 ? 'active' : 'white_item'">
<div>有礼</div>
</div>
<div class="line_item" :class="index == 2 ? 'active' : 'white_item'">
<div>一等奖</div>
</div>
<div class="line_item" :class="index == 3 ? 'active' : 'white_item'">
<div>谢谢参与</div>
</div>
<div class="line_item" :class="index == 0 ? 'active' : 'white_item'">
<div>特等奖</div>
</div>
<div class="line_item" @click="goLottery()">
立即抽奖
</div>
<div class="line_item" :class="index == 4 ? 'active' : 'white_item'">
<div>二等奖</div>
</div>
<div class="line_item" :class="index == 7 ? 'active' : 'white_item'">
<div>谢谢参与</div>
</div>
<div class="line_item" :class="index == 6 ? 'active' : 'white_item'">
<div>三等奖</div>
</div>
<div class="line_item" :class="index == 5 ? 'active' : 'white_item'">
<div>有礼</div>
</div>
 
css:

.active{

background-color: #fffea5 !important;

}

.white_item{

background-color: #fff;

}

js:

data(){

  index: 3,    // 当前转动到哪个位置,起点位置

count: 8,    // 总共有多少个位置

timer: 0,    // 每次转动定时器

speed: 200,   // 初始转动速度

times: 0,    // 转动次数

cycle: 30,   // 转动基本次数:即至少需要转动多少次再进入抽奖环节

prize: -1,   // 中奖位置

}

goLottery(){

  this.startRoll();

}

// 开始转动

startRoll () {

this.times += 1  // 转动次数

this.oneRoll()  // 转动过程调用的每一次转动方法,这里是第一次调用初始化

this.usePrize()

},

// 每一次转动

oneRoll () {

let index = this.index  // 当前转动到哪个位置

const count = 8  // 总共有多少个位置

index += 1

if (index > count - 1) {

index = 0

}

this.index = index

},

usePrize() {

// 如果当前转动次数达到要求 && 目前转到的位置是中奖位置

if (this.times > this.cycle + 10 && this.prize === this.index) {

clearTimeout(this.timer)   // 清除转动定时器,停止转动

this.times = 0

} else {

if (this.times < this.cycle) {

this.speed -= 5   // 加快转动速度

}

this.timer = setTimeout(this.startRoll, this.speed)

}

},

 

vue -- 九宫格抽奖的更多相关文章

  1. Js写九宫格抽奖

    国庆出去转了一圈,回来及时把以前写的一些有用的在这儿记录一下 --------------------------------------------我是分割线-------------------- ...

  2. PHP+Ajax微信手机端九宫格抽奖实例

    PHP+Ajax结合lottery.js制作的一款微信手机端九宫格抽奖实例,抽奖完成后有收货地址添加表单出现.支持可以设置中奖概率等. 奖品列表 <div class="lottery ...

  3. php+lottery.js制作九宫格抽奖实例

    php+lottery.js制作九宫格抽奖实例,本抽奖功能效果表现好,定制方便简单,新手学习跟直接拿来用都非常不错,兼容IE.火狐.谷歌等浏览器. 引入抽奖插件lottery.js <scrip ...

  4. 基于VUE的九宫格抽奖功能

    HTML代码: <template> <div class="luckDraw"> <title-bar :title="title&quo ...

  5. 【javascript】九宫格抽奖组件设计

    一些主要点 1. 转圈的顺序(顺时针或者逆时针): 2. 转圈的速率(从慢到快再到慢): 3. 位置的问题(下一次抽奖的起始位置是上一次抽奖的结束位置): 4. 转圈的圈数或者移动的次数. 基本原理 ...

  6. 九宫格抽奖HTML+JS版

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  7. JS:九宫格抽奖转盘实例

    工作需要,所以做了个抽奖转盘的插件,当然这里只做最简单的演示.可以用于取代一些flash抽奖程序. 机制说明: 1.通过定义lottery-unit来控制节点的个数及索引: 2.通过设置lottery ...

  8. jq demo 九宫格抽奖

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  9. 用jQuery编写简单九宫格抽奖

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. windows下解决python输出utf-8中文

    class UnicodeStreamFilter: def __init__(self, target): self.target = target self.encoding = 'utf-8' ...

  2. linux:安装mysql管理工具phpmyadmin

    1.下载phpmyadmin,下载地址:http://www.phpmyadmin.net/ 2.解压到/var/www/html/phpmyadmin/ 3.修改配置 cd /var/www/htm ...

  3. java根据GPS(经纬度)获取地理位置

    package cn.antiy.weiqing.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONAr ...

  4. 第一类对象-> 函数名 -> 变量名

    函数对象对象可以像变量一样进行赋值 还可以作为列表的元素进行使用 可以作为返回值返回 可以作为参数进行传递 # def fn(): # print("我叫fn") # fn() # ...

  5. 【转】【CUBE】Oracle分组函数之CUBE魅力

    http://blog.itpub.net/519536/viewspace-610997/ Oracle的CUBE与ROLLUP功能很相似,也是在数据统计分析领域的一把好手.  关于ROLLUP的查 ...

  6. 重新指派usb转串口模块在linux系统中的设备调用名称

    How to remap /dev/ttyUSB* to a specific name to be called by my program. How to map /dev/ttyUSB* to ...

  7. ELK测试安装

    https://blog.csdn.net/guyan0319/article/details/78749639 https://www.cnblogs.com/frankdeng/p/9139035 ...

  8. docker资料转载

    Docker之理解image,container和storage-driver centos7创建docker tomcat镜像 Linux Namespace和Cgroup

  9. Xshell 用鼠标选中一段文字后自动换行

    现象: 使用Xshell连接远程服务器,一般选中都是鼠标选中,然后按快捷键 Ctrl+Insert复制,Shift+Insert粘贴. 可是当选中后松开鼠标,这时候仿佛在xshell里自动输了一个回车 ...

  10. git的团队协作开发

    title: git的团队协作开发 date: 2018-04-24 14:00:03 tags: [git] --- 项目负责人创建组织架构 在控制面板中点击组织按钮,添加组织,在这里可以把组织理解 ...