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. vue中实时监听对象或变量的变化

    demo中监听了Input的变化,主要用到的是watch 1. 监听单个对象: <template> <div class="personal-center"&g ...

  2. 安全测试6_Web安全工具第一节(浏览器入门及扩展)

    今天来学习下浏览器的功能,浏览器是我们经常用到但是功能却很强大的一个东东,我们经常用到的无非是三种(谷歌.火狐.IE) 1.浏览器功能介绍: 下面以谷歌浏览器(Chrome版本为56)为例,介绍下,懂 ...

  3. java的list遍历

    for(String str : list) {//增强for循环,其内部实质上还是调用了迭代器遍历方式,这种循环方式还有其他限制,不建议使用. System.out.println(str); } ...

  4. 企业项目构建学习(一)maven

    <mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> & ...

  5. android_自定义布局例子

    为什么要写自定义布局: 1.在实现大量重复的子按键或者子布局时,如果一个一个去复写工作量庞大,就需要创建自定义布局直接导入布局里,可以节省大量的时间 创建自定义布局的步骤: 1.编写一个自定义xml布 ...

  6. 使用jQuery编辑删除页面内容,两种方式

    第一种,比较少的编辑用这种,直接在那块内容上编辑,失去焦点即完成 前几天做编辑框的时候,需要只修改一个状态 //编辑角色 function editTr($this){ thatTd=$($this) ...

  7. IdentityServer4 接口说明

    在.net core出来以后很多人使用identityServer做身份验证. ids4和ids3的token验证组件都是基于微软的oauth2和bearer验证组件.园子里也很多教程,我们通过教程了 ...

  8. <Linux> SSH配置之后 SHH slave1 测试 error:SSH: command not found

    首先要查看一下ssh命令存在何处 # which ssh /usr/bin/ssh 使用ssh的绝对路径 # /usr/bin/ssh slave1Welcome to Ubuntu 16.04 LT ...

  9. 25.安装配置phantomjs

    1.官网下载windows版本:http://phantomjs.org/download.html2.下载完解压,将PhantomJS可执行文件配置到环境变量里.比如: 将 E:\Soft\soft ...

  10. php 目录

    1.laravel pswd  oauth2 2.理解二叉树 3.IOC容器 4.微信支付 4.1 微信支付申请 5.DI 6.支付宝 支付H5 7.html 转 word 8.php-fpm 启动详 ...