HTML代码:

<template>
<div class="luckDraw">
<title-bar :title="title"></title-bar>
<div class="container">
<div class="turntable-wrapper">
<div class="luck-wrapper">
<p class="integral">我的积分: <span>1000</span></p>
<ul class="nineGrid">
<li class="row">
<div v-for="(n, key) in 3" :key="n" :class="index === key ? `active` : ``">
<div class="wrapper">
<img src="../../assets/luck-icon.png" alt="">
<p>8金转</p>
</div>
<div class="mask"></div>
</div>
</li>
<li class="row">
<div :class="index === 7 ? 'active': ''">
<div class="wrapper">
<img src="../../assets/luck-icon.png" alt="">
<p>128金转</p>
</div>
<div class="mask"></div>
</div>
<div class="getLuck" @click="startLottery">
<p>立即<br>抽奖</p>
</div>
<div :class="index === 3 ? 'active': ''">
<div class="wrapper">
<img src="../../assets/luck-icon.png" alt="">
<p>128金转</p>
</div>
<div class="mask"></div>
</div>
</li>
<li class="row">
<div v-for="(n, key) in 3" :key="n" :class="index === 6-key ? `active` : ``">
<div class="wrapper">
<img src="../../assets/luck-icon.png" alt="">
<p>256金转</p>
</div>
<div class="mask"></div>
</div>
</li>
</ul>
</div> <p class="share">分享领积分 <i class="icon-go"></i></p> <div class="rule">
<p class="rule-title">活动规则</p>
<ul class="rule-main">
<li>1、活动时间:2017年9月8日起;</li>
<li>2、活动期间,股事汇用户每次抽奖消耗20积分,抽奖次数不限</li>
<li>3、金钻可用于向投顾提问、送礼、赞赏;</li>
<li>4、积分赚取:每日签到、分享文章/问答/直播间、点赞、金钻充值均可获得积分哦</li>
<li>5、活动最终解释权归股事汇所有。</li>
</ul>
</div> <div></div>
</div> <LuckToast :showToast="showToast" :toastType="toastType" @closeToast="closeToast" @startLottery="startLottery"></LuckToast>
</div>
</div>
</template>

SCSS样式:

@import "~base";

.luckDraw {

  .turntable-wrapper {
padding: 0 px3rem(38);
position: relative;
@include background-cover("background-luck.png");
padding-top: px3rem(121); .luck-wrapper {
width: px3rem(300);
height: px3rem(377);
margin: 0 auto;
position: relative;
@include background-cover("background-turntable.png"); .integral {
width: 100%;
color: #6d2d00;
font-size: px3rem(16);
font-weight: normal;
text-align: center;
position: absolute;
top: px3rem(58); span {
font-weight:;
color: #ff2f4d;
}
} .nineGrid {
position: absolute;
top: px3rem(86);
left: 50%;
margin-left: px3rem(-130);
width: px3rem(260);
height: px3rem(260); li {
height: px3rem(80);
display: flex;
margin-top: px3rem(5); > div {
flex:;
margin-right: px3rem(5);
height: 100%;
text-align: center;
position: relative; .wrapper {
width: 100%;
height: 100%;
margin:;
@include background-cover("background-grid.png");
} img {
width: px3rem(46);
height: px3rem(38);
vertical-align: middle;
margin-top: px3rem(8);
} .mask {
position: absolute;
top:;
left:;
width: 100%;
height: 100%;
opacity: 0.5;
border-radius: px3rem(10);
background-color: #000;
display: none;
}
} > div.active {
.mask {
display: block;
}
} > div:first-child {
margin-left: px3rem(5);
} > div.getLuck {
@include background-cover("background-getLuck.png");
font-size:; p {
font-size: px3rem(20);
font-weight:;
color: #fff;
line-height: 1.1;
margin-top: px3rem(11);
}
}
} li:last-child {
margin-bottom: px3rem(5);
}
}
} .share {
width: px3rem(160);
height: px3rem(42);
margin: 0 auto;
text-align: center;
line-height:px3rem(42);
@include background-cover("luckShrae.png");
margin-top: px3rem(22);
color: #6d2d00;
font-size: px3rem(16);
font-weight:; .icon-go {
@include size(30);
@include background-cover("goShare-icon.png"); display: inline-block;
vertical-align: middle;
margin-bottom: px3rem(2);
}
} .rule {
margin-top: px3rem(14);
color: #fff;
font-size: px3rem(14);
padding-bottom: px3rem(39); .rule-title {
text-align: center;
position: relative;
font-size: px3rem(16);
margin-bottom: px3rem(14);
} .rule-title:before,
.rule-title:after {
content: '';
position: absolute;
top: 52%;
background: #fff;
width: 30%;
height: px3rem(1);
} .rule-title:before {
left:;
} .rule-title:after {
right:;
}
}
}
}

JS代码:

// import Utils from 'utils'
import TitleBar from 'components/TitleBar.vue'
import LuckToast from 'components/luckToast.vue' export default {
name: 'luckDraw', components: {
TitleBar,
LuckToast,
}, data () {
return {
title: '积分转盘',
index: -1, // 当前转动到哪个位置,起点位置
count: 8, // 总共有多少个位置
timer: 0, // 每次转动定时器
speed: 200, // 初始转动速度
times: 0, // 转动次数
cycle: 50, // 转动基本次数:即至少需要转动多少次再进入抽奖环节
prize: -1, // 中奖位置
click: true,
showToast: false,
toastType: 'luck',
}
}, props: { }, methods: {
// 开始抽奖
startLottery () {
if (!this.click) {
return
}
this.closeToast()
this.speed = 200
this.click = false
this.startRoll()
}, // 开始转动
startRoll () {
this.times += 1 // 转动次数
this.oneRoll() // 转动过程调用的每一次转动方法,这里是第一次调用初始化 // 如果当前转动次数达到要求 && 目前转到的位置是中奖位置
if (this.times > this.cycle + 10 && this.prize === this.index) {
clearTimeout(this.timer) // 清除转动定时器,停止转动
this.prize = -1
this.times = 0
this.click = true
this.showToast = true
this.toastType = 'comeOn'
console.log('你已经中奖了')
} else {
if (this.times < this.cycle) {
this.speed -= 10 // 加快转动速度
} else if (this.times === this.cycle) { // 随机获得一个中奖位置
const index = parseInt(Math.random() * 10, 0) || 0
this.prize = index
if (this.prize > 7) {
this.prize = 7
}
console.log(`中奖位置${this.prize}`)
} else if (this.times > this.cycle + 10 &&
((this.prize === 0 && this.index === 7) || this.prize === this.index + 1)) {
this.speed += 110
} else {
this.speed += 20
} if (this.speed < 40) {
this.speed = 40
}
this.timer = setTimeout(this.startRoll, this.speed)
}
}, // 每一次转动
oneRoll () {
let index = this.index // 当前转动到哪个位置
const count = this.count // 总共有多少个位置
index += 1
if (index > count - 1) {
index = 0
}
this.index = index
}, // 关闭弹出框
closeToast () {
this.showToast = false
},
}, beforeMount () { }, created () { }, beforeDestroy () { },
}

基于VUE的九宫格抽奖功能的更多相关文章

  1. 基于vue开发的多功能的时间选择器组件,开箱即用

    好一段时间没有写过博客了,在国庆期间心血来潮优化了一个组件,在日常开发中时常会有需求用到时间选择器,不同的项目需求可能会不一样.近期开发的几个项目中就有需求用到这样的选择器,由于以前有用到相关的组件, ...

  2. 基于vue的颜色选择器color-picker

    项目中有用到颜色选择器的童鞋们可以看过来了 关于color-picker的jquery的插件是有蛮多,不过vue组件没有吧,反正我没有找到, 虽然element-ui里面有这个,但是你愿意为了一个小功 ...

  3. 基于Vue的小日历(支持按周切换)

      基于Vue的日历小功能,可根据实际开发情况按每年.每月.每周.进行切换 <template> <div class="date"> <!-- 年份 ...

  4. 基于vue的颜色选择器vue-color-picker

    项目中有用到颜色选择器的童鞋们可以看过来了 关于color-picker的jquery的插件是有蛮多,不过vue组件没有吧,反正我没有找到, 虽然element-ui里面有这个,但是你愿意为了一个小功 ...

  5. 基于vue2.0打造移动商城页面实践 vue实现商城购物车功能 基于Vue、Vuex、Vue-router实现的购物商城(原生切换动画)效果

    基于vue2.0打造移动商城页面实践 地址:https://www.jianshu.com/p/2129bc4d40e9 vue实现商城购物车功能 地址:http://www.jb51.net/art ...

  6. 通过base64实现图片下载功能(基于vue)

    1. 使用场景 当我们处理图片下载功能的时候,如果本地的图片,那么是可以通过canvas获得图片的base64的,方法如下.但是如果图片的url存在跨域问题的话,下面的方法将行不通,这时候我们可以另辟 ...

  7. 基于Vue的WebApp项目开发(二)

    利用webpack解析和打包.vue组件页面 相关知识: vue项目中的每个页面其实都是一个.vue的文件,这种文件,Vue称之为组件页面,必须借助于webpack的vue-loader才能运行,所以 ...

  8. 一次基于Vue.Js用户体验的优化

    .mytitle { background: #2B6695; color: white; font-family: "微软雅黑", "宋体", "黑 ...

  9. 发布自己第一个npm 组件包(基于Vue的文字跑马灯组件)

    一.前言 总结下最近工作上在移动端实现的一个跑马灯效果,最终效果如下: 印象中好像HTML标签的'marquee'的直接可以实现这个效果,不过 HTML标准中已经废弃了'marquee'标签 既然HT ...

随机推荐

  1. display:inline-block引发的间隙思考

    一.导火线 没错,总有一类属性在助你轻松寻得捷径的同时,也可为你增添烦劳,比如本文的主谋display:inline-block.众前端们所诸知,其作用是将对象呈递为内联对象,但是对象的内容作为块对象 ...

  2. javascript计算对象的长度

    计算对象的长度,即获取对象属性的个数 方法一:通过for in 遍历对象,并通过hasOwnProperty判断是否是对象自身可枚举的属性 var obj = {"c1":1,&q ...

  3. Flask-配置与调试

    配置管理 复杂的项目需要配置各种环境.如果设置项很少,可以直接硬编码进来,比如下面的方式: app = Flask(__name__) app.config['DEBUG'] = True app.c ...

  4. Linux 常见目录与区别

    .   代表此层目录 ..   代表上一层目录 -   代表前一个工作目录 ~   代表『目前用户身份』所在的家目录

  5. WebGL多模型光照综合实例

      原文地址:WebGL多模型光照综合实例   WebGL是一个非常的接近硬件底层的光栅化API, 从非常类似C/C++风格的API调用方式就可以看出来, 习惯了高级语言的我们会觉得很不友好,觉得特别 ...

  6. VMware 设置共享目录

    VMware 共享目录设置 1,选择"虚拟机"->"重新安装VMware Tools"2,挂载cdrom3,拷贝VMware-tool.tar.gz 到L ...

  7. Android基础_web通信2

    一.移动客服端实现对PC端数据的操作 在PC端模拟一个数据库,实现用户的增删改查,然后在移动客服端实现对PC端数据库的操作 在PC端建立三个表 用户表(Users),员工表(Emp), 部门表(Dep ...

  8. React-Native 学习笔记-Android开发平台-开发环境搭建

    详细步骤请查看官网对应文档,BUT,有些注意事项请注意! 1,优先安装Node.js,因为后面可以使用npm安装软件, 2,注意不要使用CNPM!!!!!!!!! 3,Android Studio 请 ...

  9. Java DB访问之 JDBC

    项目说明 项目采用 maven 组织 ,jdbc 唯一的依赖就是 mysql-connector-java pom 依赖如下: <dependency> <groupId>my ...

  10. RAC+ASM 添加控制文件

    环境介绍:11g RAC 使用 ASM 磁盘组,控制文件只有一个,需要进行添加 参照 MOS 文档 How to Multiplex Control File In RAC Database (文档 ...