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. CSS3 自定义动画(animation)

    除了在之前的文章中介绍过的 CSS3 的变形 (transformation) 和转换 (transition) 外,CSS3 还有一种自由度更大的自定义动画,开发者甚至可以使用变形(transfor ...

  2. Life in Changsha 第一次scrum冲刺

    第一次冲刺任务 基于大局的全面性功能框架定位,要求能实现用户基于自己的需求进行的一系列操作. 用户故事 用户打开“生活在长大”的界面 程序首页展示校园服务,论坛等相关信息 用户选择某个功能 程序界面跳 ...

  3. JSON 序列化和解析

    概述 JSON 即 (Javascript Object Notation,Javascript 对象表示法),是在Javascript中写结构化数据的方式.而JSON本身只是一种数据格式. 通常开发 ...

  4. 北斗卫星同步时钟(NTP网络时钟服务器)成功投运世界级工程港珠澳大桥

    北斗卫星同步时钟(NTP网络时钟服务器)成功投运世界级工程港珠澳大桥 北斗卫星同步时钟(NTP网络时钟服务器)成功投运世界级工程港珠澳大桥 本文由北京华人开创科技公司提供 原址在 http://www ...

  5. Mac安装Scala

    1. 下载,解压Scala sdk,2. 配置环境变量(.bash_profile) SCALA_HOME="/Users/soft/scala_soft/scala-2.11.6" ...

  6. easyHOOK socket send recv

    代码比较简单,就不做注释了.  包含一个sockethookinject.DLL 和sockethook.exe 有一点不清楚, SetExclusiveACL可以添加当前线程的hook, 但是eas ...

  7. 深入设计电子计算器(一)——CPU指令集设计

    版权申明:本文为博主窗户(Colin Cai)原创,欢迎转帖.如要转贴,必须注明原文网址 http://www.cnblogs.com/Colin-Cai/p/8254096.html 作者:窗户 Q ...

  8. MongoDb 快速入门教程

    文章首发于[博客园-陈树义],点击跳转到原文MongoDb 快速入门教程. MongoDb 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的. 它是可扩展的 ...

  9. 五分钟学习React(四):什么是JSX

    JSX,即javscript XML,是js内定义的一套XML语法.目前是使用babel作为JSX的编译器.这也是在前几期中载入babel的原因. Facebook引入JSX是为了解决前端代码工程复杂 ...

  10. mysql 在B数据库下 创建一个与A数据库中一样的表

    1.创建数据内容与结构一致(不会复制索引以及外键) create table B.test as select * from A.test; 2.把上面的步骤分开,先复制结构 create table ...