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 Defender 无法启动

    最近win10 企业版操作系统中,Windows Defender  无法 启动,并提示消息 : to allow this app run , contact your security admin ...

  2. 微信小程序笔记<七>视图层 —— wxml

    微信小程序的视图层由 *.wxml 组成,wxml与html一样属于标签语言,但wxml与html的标签截然不一样. xwml特性 一.数据绑定 <!--wxml--> <view& ...

  3. 遇到的问题&思考

    MYSQL需要批量修改表前缀: http://jingyan.baidu.com/article/11c17a2c742561f446e39d2f.html Select CONCAT( 'ALTER ...

  4. glob获取指定目录下的东西+更改工作目录

    一:不更改工作目录 import glob path = 'image/imgs/*.jpg' # 正则匹配 指定路径 file_path = glob.glob(path) # 即可获取所有jpg的 ...

  5. [UGUI]图文混排(七):动态表情

    帧动画脚本: http://www.cnblogs.com/lyh916/p/9194823.html 这里的动态表情,我使用的是固定间隔去刷新Image上的Sprite来实现的,即帧动画.这里可以将 ...

  6. 转载:Bootstrap 源码解析

    Bootstrap 源码解析 前言 Bootstrap 是个CSS库,简单,高效.很多都可以忘记了再去网站查.但是有一些核心的东西需要弄懂.个人认为弄懂了这些应该就算是会了.源码看一波. 栅格系统 所 ...

  7. Shell 编程(实例二)

    创建一个脚本,为指定硬盘创建分区 1.列出当前系统所有磁盘,让用户选择,如果选择quit则退出脚本:如果选择错误,则重新选择 2.当用户选择完成后,询问是否继续 3.抹除选择磁盘上的分区,为其创建三个 ...

  8. django 使用mysql 数据库

    在 django 创建项目中 默认使用的是  splite3 数据库,不是mysql 数据库,要使用mysql ,要做一些配置: 在 settings.py 中修改如下: DATABASES = { ...

  9. Dubbo 服务容错Hystrix

    一.服务者 1.pom <dependency> <groupId>org.springframework.cloud</groupId> <artifact ...

  10. 区分slice,splice和split方法

    1.slice(数组) 用法:array.slice(start,end) 解释:该方法是对数组进行部分截取,并返回一个数组副本:参数start是截取的开始数组索引,end参数等于你要取的最后一个字符 ...