小程序实现筛子抽奖


Posted in Javascript onMay 26, 2021

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

效果图

小程序实现筛子抽奖

<!--pages/shaizi/index.wxml-->
<view class="container">
  <view class="shaizi_box {{activeTrue}}" style="transform: rotateX({{rotateX}}deg) rotateY({{rotateY}}deg) rotateZ({{rotateZ}}deg);">
    <view class="shaizi">1</view>
    <view class="shaizi">2</view>
    <view class="shaizi">3</view>
    <view class="shaizi">4</view>
    <view class="shaizi">5</view>
    <view class="shaizi">6</view>
  </view>
  <text class="view"></text>
  <button bindtap="gamePlay">PLAY</button>
</view>
// pages/shaizi/index.js
var dingshiqi1 = 0;
var dingshiqi2 = 0;
var dingshiqi3 = 0;
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    activeTrue:"active1",
    rotateX:0,
    rotateY:0,
    rotateZ:0,
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  gamePlay:function(){
    let _that = this;
    this.setData({
      activeTrue:"active2",
      rotateX:0,
      rotateY:0,
      rotateZ:0,
    })
    clearInterval(dingshiqi3)
    let _posible = [
      { value: 1, x: 0, y: 0 },
      { value: 6, x: 180, y: 0 },
      { value: 3, x: 0, y: -90 },
      { value: 4, x: 0, y: 90 },
      { value: 5, x: -90, y: 0 },
      { value: 2, x: 90, y: 0 },
     ]
    // 准备抽取的随机数
    let _random = Math.floor(Math.random() * 6);
    dingshiqi1 = setTimeout(() => {
      _that.setData({
        rotateX:360,
        rotateY:250,
        rotateZ:0,
      })
     }, 0);
     dingshiqi2 = setTimeout(() => {
      _that.setData({
        rotateX:_posible[_random].x,
        rotateY:_posible[_random].y,
      })
      dingshiqi3 = setTimeout(() => {
        _that.setData({
          activeTrue:"active1",
        })
      }, 4500);
     }, 800);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
 
  }
})
/* pages/shaizi/index.wxss */
@keyframes rotate {
  to {
   transform: rotateX(360deg) rotateY(250deg);
  }
 }
 @keyframes shaiziCss{
  20%{
   transform: rotateX(20deg);
  }
  60%{
   transform: rotateX(20deg) rotateY(200deg);
  }
  100%{
   transform: rotateX(100deg) rotateY(1000deg) rotateZ(-100deg);
  }
 }
 .shaizi_box {
  width: 200rpx;
  height: 200rpx;
  margin: 200rpx auto;
  position: relative;
  transform-style: preserve-3d;
  animation-duration: 3s;
  animation-timing-function: linear;
  transition: all 1s;
 }
.shaizi_box.active1{
  animation: rotate 5s linear 0s infinite alternate !important;
}
.shaizi_box.active2{
  animation: shaiziCss 2s !important;
}
.shaizi_box .shaizi {
  width: 200rpx;
  height: 200rpx;
  display: flex;
  position: absolute;
  left: 0;
  top: 0;
  border: 1px solid #000;
  background: rgb(253, 250, 250);
  border-radius: 20rpx;
  font-size: 100rpx;
  color: red;
  text-align: center;
 }
 .shaizi:nth-child(1) {
  justify-content: center;
  align-items: center;
  transform: translateZ(100rpx);
 }
 .shaizi:nth-child(2) {
  justify-content: space-around;
  align-items: center;
  transform: rotateX(-90deg) translateZ(100rpx);
 }
 .shaizi:nth-child(3) {
  justify-content: space-around;
  align-items: center;
  flex-wrap: wrap;
  transform: rotateY(90deg) translateZ(100rpx);
 }
 .shaizi:nth-child(4) {
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  transform: rotateY(-90deg) translateZ(100rpx);
 }
 .shaizi:nth-child(5) {
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  transform: rotateX(90deg) translateZ(100rpx);
 }
 .shaizi:nth-child(6) {
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  transform: rotateX(-180deg) translateZ(100rpx);
}

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

Javascript 相关文章推荐
js程序中美元符号$是什么
Jun 05 Javascript
jquery仿搜索自动联想功能代码
May 23 Javascript
jQuery纵向导航菜单效果实现方法
Dec 19 Javascript
JavaScript该如何学习 怎样轻松学习JavaScript
Jun 12 Javascript
浅谈JS中的常用选择器及属性、方法的调用
Jul 28 Javascript
在vue中使用vue-echarts-v3的实例代码
Sep 13 Javascript
微信小程序实现登录遮罩效果
Nov 01 Javascript
vue登录注册实例详解
Sep 14 Javascript
JavaScript位置参数实现原理及过程解析
Sep 14 Javascript
vue 防止页面加载时看到花括号的解决操作
Nov 09 Javascript
vue实现两个区域滚动条同步滚动
Dec 13 Vue.js
JavaScript实现酷炫的鼠标拖尾特效
Feb 18 Javascript
详解vue身份认证管理和租户管理
ES6 解构赋值的原理及运用
vue点击弹窗自动触发点击事件的解决办法(模拟场景)
js Proxy的原理详解
May 25 #Javascript
解析原生JS getComputedStyle
80行代码写一个Webpack插件并发布到npm
Ajax请求超时与网络异常处理图文详解
May 23 #Javascript
You might like
PHP脚本数据库功能详解(下)
2006/10/09 PHP
用php将任何格式视频转为flv的代码
2009/09/03 PHP
PHP5.5在windows安装使用memcached服务端的方法
2014/04/16 PHP
PHP结合Ueditor并修改图片上传路径
2016/10/16 PHP
Javascript表格翻页效果实现思路及代码
2013/08/23 Javascript
JavaScript中window.showModalDialog()用法详解
2014/12/18 Javascript
babel基本使用详解
2017/02/17 Javascript
Bootstrap modal 多弹窗之叠加显示不出弹窗问题的解决方案
2017/02/23 Javascript
Vue.js 插件开发详解
2017/03/29 Javascript
JavaScript数组基于交换的排序示例【冒泡排序】
2018/07/21 Javascript
vuejs选中当前样式active的实例
2018/08/22 Javascript
浅谈layui使用模板引擎动态渲染元素要注意的问题
2019/09/14 Javascript
JavaScript字符和ASCII实现互相转换
2020/06/03 Javascript
[00:35]DOTA2上海特级锦标赛 VP战队宣传片
2016/03/04 DOTA
[11:12]2018DOTA2国际邀请赛寻真——绿色长城OpTic
2018/08/10 DOTA
[03:06]2018年度CS GO最具人气解说-完美盛典
2018/12/16 DOTA
Python中使用异常处理来判断运行的操作系统平台方法
2015/01/22 Python
Python利用Beautiful Soup模块创建对象详解
2017/03/27 Python
python使用json序列化datetime类型实例解析
2018/02/11 Python
如何用C代码给Python写扩展库(Cython)
2019/05/17 Python
Python3 实现爬取网站下所有URL方式
2020/01/16 Python
通过代码实例解析Pytest运行流程
2020/08/20 Python
python中turtle库的简单使用教程
2020/11/11 Python
详解python polyscope库的安装和例程
2020/11/13 Python
python 对xml解析的示例
2021/02/27 Python
怀旧收藏品和经典纪念品:Betty’s Attic
2018/08/29 全球购物
乌克兰数字设备、配件和智能技术的连锁商店:KTC
2020/08/18 全球购物
旅游节目策划方案
2014/05/26 职场文书
酒店管理求职信
2014/06/09 职场文书
市委召开党的群众路线教育实践活动总结大会报告
2014/10/21 职场文书
2015年基建工作总结范文
2015/05/23 职场文书
博物馆观后感
2015/06/05 职场文书
CSS3 制作的悬停缩放特效
2021/04/13 HTML / CSS
Spring Boot 启动、停止、重启、状态脚本
2021/06/26 Java/Android
SpringBoot集成MongoDB实现文件上传的步骤
2022/04/18 MongoDB
mysql序号rownum行号实现方式
2022/12/24 MySQL