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. Spring Security数据库管理

    要实现数据库管理用户角色及权限,需要自定义用户登录功能,Spring Security已经为我们提供了接口UserDetailService.需要以下表: 用户表 角色表 权限表 用户角色关系表 权限 ...

  2. 【Selenium-WebDriver问题篇】Selenium实现元素的拖拽(java版)(转)

    https://blog.csdn.net/u010503127/article/details/51381284 Selenium实现元素的拖拽(java版) [前言] 自从淘宝网登陆页出现滑块验证 ...

  3. Fiddler设置抓取https请求

    环境准备 1.安装最新版本的Fiddler程序 官网地址:https://www.telerik.com/fiddler 本文写的时候,fiddler最新的版本为5.0 2.安装fiddler证书生成 ...

  4. linux中测试py脚本使用debug模式

    python -mtrace --trace ping_host.py

  5. android 开发 singleTask启动模式下传值的坑

    日常填坑. 做了什么操作引起的?如下: 在活动A 启动模式设置为singleTask ,然后再用活动A启动活动B,活动B启动活动C. 现在我的活动C要使用intent携带值去启动活动A.在活动A中正常 ...

  6. 网站分析基础及KPI实践

    一:网站分析是什么? 网站分析(Web Analytics)即网站访客行为分析,通过对网站数据进行定量和定性的分析,来不断驱动和提高访问者在网站中的体验,并将访客转化为你的商业目标(在线及离线KPI) ...

  7. Exchange Server and Update Rollup Build Numbers

    原文链接https://social.technet.microsoft.com/wiki/contents/articles/240.exchange-server-and-update-rollu ...

  8. remote staging type or host is not specified

    idea在tomcat配置中显示此错误 配置下面选上就好了

  9. putty使用秘钥对登录百度云系统全过程

    使用秘钥对登录百度云系统全过程 1在百度云生成秘钥对 并且绑定要登录的IP 1)创建 2) 创建成功后,会自动下载私钥到本地 3)绑定 4)绑定完毕 2把下载到本地的私钥使用putty key gen ...

  10. centos 共享文件目录

    # yum install nfs-utils # mkdir /storage # cat /etc/exports /storage *(fsid=0,rw,sync,no_root_squash ...