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. Linux如何让进程在后台运行的三种方法详解

    问题分析: 我们知道,当用户注销(logout)或者网络断开时,终端会收到 HUP(hangup)信号从而关闭其所有子进程.因此,我们的解决办法就有两种途径:要么让进程忽略 HUP 信号,要么让进程运 ...

  2. collections --Counter

    collections 模块--Counter 目的是用来跟踪值出现的次数.是一个无序的容器类型,以字典的键值对形式存储,其中元素为 key,其计数作为 value.计数值可以是任意的 Integer ...

  3. mac安装mysql的两种方法(含配置)

    1.使用安装包安装mysql 双击打开安装文件 双击pkg文件安装 一路向下,记得保存最后弹出框中的密码(它是你mysql root账号的密码) 正常情况下,安装成功. 此时只是安装成功,但还需要额外 ...

  4. Python数据分析与可视化(经典学习资料)

    Numpy:来存储和处理大型矩阵,比Python自身的嵌套列表(nested list structure)结构要高效的多,本身是由C语言开发.这个是很基础的扩展,其余的扩展都是以此为基础.数据结构为 ...

  5. ES6小点心之通用弹窗

    小点心,顾名思义,开箱即食,拿来即用. 前端业务逻辑主要分为[交互效果]和[数据展示]两方面.数据展示可使用 MVVM 框架来实现.前端的交互效果常用的也就那么几种,比如弹窗,楼层定位,倒计时,下拉刷 ...

  6. 做了一个web版的 MyBatis Generator

    mybatis 官方提供了 MyBatis Generator ,可以通过 xml 配置文件的方式使用,例如自己写调用脚本,或者使用 mvn 插件的方式,其实实现起来还是很简单的.虽然简单,但还是不够 ...

  7. String常用的方法

    l String: 字符串类,字符串是常量:它们的值在创建之后不能更改 l 方法 boolean equals(Object obj) 判断两个字符串中的内容是否相同 boolean equalsIg ...

  8. [搬运] 写给 C# 开发人员的函数式编程

    原文地址:http://www.dotnetcurry.com/csharp/1384/functional-programming-fsharp-for-csharp-developers 摘要:作 ...

  9. 开发问题(一)在windows和linux端口占用问题

    前言 今天在MyEclipse中使用tomcat发现tomcat端口8080竟然被占用了,所以就找了一下解决办法共参考! 在网络程序的调试过程中,经常发生一些出乎意料的事情,比如创建一个TCP服务失败 ...

  10. bzoj 1935: [Shoi2007]Tree 园丁的烦恼

    Description 很久很久以前,在遥远的大陆上有一个美丽的国家.统治着这个美丽国家的国王是一个园艺爱好者,在他的皇家花园里种植着各种奇花异草.有一天国王漫步在花园里,若有所思,他问一个园丁道: ...