微信小程序实现翻牌抽奖动画


Posted in Javascript onSeptember 21, 2020

本文实例为大家分享了微信小程序实现翻牌抽奖的具体代码,供大家参考,具体内容如下

效果图如下所示

微信小程序实现翻牌抽奖动画

这里做的比较简陋,就花了一点时间实现了翻牌抽奖效果,提供思路

.wxml

<view class="button" bindtap="again">重新翻牌</view>
<view class="curin-index">
 <view bindtap="{{whether?'':'tamin'}}" wx:for="{{9}}" wx:key="index" data-index="{{index+1}}" class="currin {{really == index+1?'animt':''}} {{really != index+1 && surplus?'animt':''}} {{really == ''?'cinton'+(index+1):''}}" style="{{really == index+1 && implement > 1?'background-image: linear-gradient(45deg, #f43f3b, #ec008c);':''}}{{really != index+1 && surplus && implement > 2?'background-image: linear-gradient(45deg, #39b54a, #8dc63f);':''}}">
  {{really == index+1?flop:''}}{{really != index+1 && really != ''?biutin:''}}{{really == ''?'点击翻牌':''}}
 </view>
</view>

.wxss

view{
 box-sizing: border-box;
}
.button{
 width: 40%;
 height: 80rpx;
 line-height: 80rpx;
 background-color: #fadbd9;
 color: #e54d42;
 text-align: center;
 border-radius: 10rpx;
 margin: 30rpx 30%;
 float: left;
 position: relative;
}
.curin-index{
 width: 100%;
 float: left;
}
.currin{
 margin-left: 4%;
 margin-top: 50rpx;
 width: 28%;
 float: left;
 background-image: linear-gradient(45deg, #0081ff, #1cbbb4);
 color: #fff;
 text-align: center;
 height: 200rpx;
 line-height: 200rpx;
 border-radius: 10rpx;
 position: relative;
}
.currin::before {
 content: "";
 display: block;
 background: inherit;
 filter: blur(10rpx);
 position: absolute;
 width: 100%;
 height: 100%;
 top: 10rpx;
 left: 10rpx;
 z-index: -1;
 opacity: 0.4;
 transform-origin: 0 0;
 border-radius: inherit;
 transform: scale(1, 1);
}
.cinton1{
 animation: cinton1 alternate linear 2 1s;
}
@keyframes cinton1{
 from {
  top: 0;
  left: 0;
 }
 to {
  top: 230rpx;
  left: 230rpx;
 }
}
.cinton2{
 animation: cinton2 alternate linear 2 1s;
}
@keyframes cinton2{
 from {
  top: 0;
  left: 0;
 }
 to {
  top: 230rpx;
  left: 0rpx;
 }
}
.cinton3{
 animation: cinton3 alternate linear 2 1s;
}
@keyframes cinton3{
 from {
  top: 0;
  left: 0;
 }
 to {
  top: 230rpx;
  left: -230rpx;
 }
}
.cinton4{
 animation: cinton4 alternate linear 2 1s;
}
@keyframes cinton4{
 from {
  top: 0;
  left: 0;
 }
 to {
  top: 0rpx;
  left: 230rpx;
 }
}
.cinton6{
 animation: cinton6 alternate linear 2 1s;
}
@keyframes cinton6{
 from {
  top: 0;
  left: 0;
 }
 to {
  top: 0rpx;
  left: -230rpx;
 }
}
.cinton7{
 animation: cinton7 alternate linear 2 1s;
}
@keyframes cinton7{
 from {
  top: 0;
  left: 0;
 }
 to {
  top: -230rpx;
  left: 230rpx;
 }
}
.cinton8{
 animation: cinton8 alternate linear 2 1s;
}
@keyframes cinton8{
 from {
  top: 0;
  left: 0;
 }
 to {
  top: -230rpx;
  left: 0rpx;
 }
}
.cinton9{
 animation: cinton9 alternate linear 2 1s;
}
@keyframes cinton9{
 from {
  top: 0;
  left: 0;
 }
 to {
  top: -230rpx;
  left: -230rpx;
 }
}
.animt{
 animation: fanzhuan 1.2s;
}
@keyframes fanzhuan{
 0% {
  transform: perspective(150px) rotateY(0deg);
 } 
 50% {
  transform: perspective(150px) rotateY(0deg);
 } 
 100% {
  transform: perspective(150px) rotateY(179.9deg);
 }
}

.js

Page({
 data: {
  whether: false,
  flop:'点击翻牌',
  really:'',
  implement: 0,
  surplus:false,
  biutin:'点击翻牌',
 }, 
 again:function(e){
  if (this.data.implement == 3 || this.data.implement == 0){
   this.setData({
    whether: false,
    flop: '点击翻牌',
    really: '',
    implement: 0,
    surplus: false,
    biutin: '点击翻牌',
   })
  }else{
   wx.showToast({
    title: '正在执行抽奖中...',
    icon: 'none',
    duration: 2000
   })
   return false
  }
 },
 tamin:function(e){
  let that = this
  let index = e.currentTarget.dataset.index
  that.setData({
   whether:true,
   really: index,
   implement:1,
  })
  setTimeout(function () {
   that.setData({
    flop: '',
   })
  }, 500)
  setTimeout(function () {
   that.setData({
    flop:'有奖品',
    surplus:true,
    implement: 2,
   })
  }, 1200)
  setTimeout(function () {
   that.setData({
    biutin: '',
   })
  }, 1700)
  setTimeout(function () {
   that.setData({
    biutin: '没有奖品',
    implement:3,
   })
  }, 2500)
 }
})

为大家推荐现在关注度比较高的微信小程序教程一篇:《微信小程序开发教程》小编为大家精心整理的,希望喜欢。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
javascript从image转换为base64位编码的String
Jul 29 Javascript
javascript实现禁止鼠标滚轮事件
Jul 24 Javascript
jQuery实现模仿微博下拉滚动条加载数据效果
Dec 25 Javascript
JavaScript浮点数及运算精度调整详解
Oct 21 Javascript
Vue.js组件tabs实现选项卡切换效果
Dec 01 Javascript
bootstrap中模态框、模态框的属性实例详解
Feb 17 Javascript
Bootstrap组合上、下拉框简单实现代码
Mar 06 Javascript
微信小程序 标签传入数据
May 08 Javascript
通过源码分析Vue的双向数据绑定详解
Sep 24 Javascript
JS实现方形抽奖效果
Aug 27 Javascript
node.js实现http服务器与浏览器之间的内容缓存操作示例
Feb 11 Javascript
vue css 相对路径导入问题级踩坑记录
Jun 05 Vue.js
不依任何赖第三方,单纯用vue实现Tree 树形控件的案例
Sep 21 #Javascript
微信小程序实现转盘抽奖
Sep 21 #Javascript
结合axios对项目中的api请求进行封装操作
Sep 21 #Javascript
微信小程序实现打卡签到页面
Sep 21 #Javascript
微信小程序实现签到弹窗动画
Sep 21 #Javascript
解决vue prop传值default属性如何使用,为何不生效的问题
Sep 21 #Javascript
微信小程序实现日历签到
Sep 21 #Javascript
You might like
Linux fgetcsv取得的数组元素为空字符串的解决方法
2011/11/25 PHP
PHP file_get_contents设置超时处理方法
2013/09/30 PHP
详解js异步文件加载器
2016/01/24 PHP
PHP后台实现微信小程序登录
2018/08/03 PHP
php操作redis命令及代码实例大全
2020/11/19 PHP
DOMAssitant最新版 DOMAssistant 2.5发布
2007/12/25 Javascript
jquery动态改变form属性提交表单
2014/06/03 Javascript
JavaScript实现动态创建CSS样式规则方案
2014/09/06 Javascript
全面解析Bootstrap表单使用方法(表单控件)
2015/11/24 Javascript
在JavaScript中使用JSON数据
2016/02/15 Javascript
JS+DIV实现的卷帘效果示例
2017/03/22 Javascript
JavaScript输出所选择起始与结束日期的方法
2017/07/12 Javascript
JS实现的冒泡排序,快速排序,插入排序算法示例
2019/03/02 Javascript
JS实现从对象获取对象中单个键值的方法示例
2019/06/05 Javascript
Vue打包后访问静态资源路径问题
2019/11/08 Javascript
[01:05:12]2014 DOTA2国际邀请赛中国区预选赛 TongFu VS CIS-GAME
2014/05/21 DOTA
简单讲解Python中的闭包
2015/08/11 Python
详解用python实现简单的遗传算法
2018/01/02 Python
详解如何用django实现redirect的几种方法总结
2018/11/22 Python
python找出列表中大于某个阈值的数据段示例
2019/11/24 Python
在python中实现求输出1-3+5-7+9-......101的和
2020/04/02 Python
如何从csv文件构建Tensorflow的数据集
2020/09/21 Python
python 装饰器的使用示例
2020/10/10 Python
纯css3制作煽动翅膀的蝴蝶的示例
2018/04/23 HTML / CSS
微软台湾官方网站:Microsoft台湾
2018/08/15 全球购物
GC是什么?为什么要有GC?
2013/12/08 面试题
社区包粽子活动方案
2014/01/21 职场文书
妈妈的账单教学反思
2014/02/06 职场文书
班级心理活动总结
2014/07/04 职场文书
2015年幼儿园元旦游艺活动策划书
2014/12/09 职场文书
英语教师求职信范文
2015/03/20 职场文书
指导老师鉴定意见
2015/06/05 职场文书
2016春季校长开学典礼致辞
2015/11/26 职场文书
Python中基础数据类型 set集合知识点总结
2021/08/02 Python
Redis sentinel哨兵集群的实现步骤
2022/07/15 Redis
Python pyecharts案例超市4年数据可视化分析
2022/08/14 Python