Hello,大家好,我是CodingSir,一枚十多年的程序员,同时也是一名在读研究生,关注我,且看一个平凡的程序员如何在自我成长,CodingSir只为各位小伙伴提供编程相关干货知识,希望在自我蜕变的路上,我们一起努力,努力什么时候开始都不晚,我,从现在开始做起!
一、前言
最近的一个项目因为目前新增用户和日活用户不断下滑,所以结合情况需要加一个抽奖大转盘,所以本篇就把前端实现抽奖大转盘的代码分享出来,本次大转盘主要是使用js+vue.js实现的,希望可以给你带来一丝灵感。
二、抽奖大转盘实现步骤
2.1 需求原型
要求实现一个抽奖大转盘的功能
2.2 编码实现
主要分为3块实现,分别是:1.页面标签绘制 2.页面标签样式设置 3.页面交互,主要是结合js+vue.js实现抽奖的动作交互行为
页面绘制:
<div id="app">
<!-- 标题-->
<h1 style="color: white;text-align: center;margin: 50px">CodingSir-抽奖大转盘</h1>
<!-- 抽奖部分-->
<div class="container-out">
<div class="container-in">
<div class="content-out" v-for="(box,index) in list"
:style="{left:box.left+'px',top:box.top+'px','background-color':index==indexSelect?colorSelect:colorDefault}">
<img class="pond-name-img" :src="box.image_url" alt="">
<div class="pond-name">{
{box.name}}</div>
</div>
</div>
<div class="start-btn" v-on:click="startBtn">
<img src="../imgs/pond-button.png" style="height:80px;width:100%;" alt="">
<img src="../imgs/pond-cj.png" :style="{'top':btntop+'px'}"
style="position:absolute;left:5px;height:68px;width:89px;top:0;" alt="">
</div>
<div class="circle" v-for="(item,index) in circleList"
:style="{'top':item.topCircle+'px','left':item.leftCircle+'px','background-color':index%2==0?colorFirst:colorSecond}">
</div>
</div>
<!-- 抽奖结果展示-->
<div class="prize" v-show="prize==1">
<div class="prize-box">
<img class="prize-img" src="../imgs/pond-success.png" alt="">
<div class="prize-msg">