小程序实现筛子抽奖


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 相关文章推荐
jQuery EasyUI API 中文文档 - Panel面板
Sep 30 Javascript
javascript模拟订火车票和退票示例
Apr 24 Javascript
JS中Location使用详解
May 12 Javascript
浅谈javascript中基本包装类型
Jun 03 Javascript
js编写一个简单的产品放大效果代码
Jun 27 Javascript
jquery siblings获取同辈元素用法实例分析
Jul 25 Javascript
BootstrapTable+KnockoutJS自定义T4模板快速生成增删改查页面
Aug 01 Javascript
jQuery插件FusionCharts实现的3D柱状图效果实例【附demo源码下载】
Mar 03 Javascript
Vue.js基础学习之class与样式绑定
Mar 20 Javascript
基于JavaScript实现的快速排序算法分析
Apr 14 Javascript
JS轮播图实现简单代码
Feb 19 Javascript
JavaScript实现Tab选项卡切换
Feb 13 Javascript
详解vue身份认证管理和租户管理
ES6 解构赋值的原理及运用
vue点击弹窗自动触发点击事件的解决办法(模拟场景)
js Proxy的原理详解
May 25 #Javascript
解析原生JS getComputedStyle
80行代码写一个Webpack插件并发布到npm
Ajax请求超时与网络异常处理图文详解
May 23 #Javascript
You might like
PHP将DateTime对象转化为友好时间显示的实现代码
2011/09/20 PHP
PHP批量采集下载美女图片的实现代码
2013/06/03 PHP
PHP登陆后跳转到登陆前页面实现思路及代码
2014/01/17 PHP
Session 失效的原因汇总及解决丢失办法
2015/09/30 PHP
laravel实现上传图片并在页面显示的例子
2019/10/14 PHP
CentOS7系统搭建LAMP及更新PHP版本操作详解
2020/03/26 PHP
Javascript读取cookie函数代码
2010/10/16 Javascript
jQuery UI Autocomplete 体验分享
2012/02/14 Javascript
一道常被人轻视的web前端常见面试题(JS)
2016/02/15 Javascript
浅谈js中的延迟执行和定时执行
2016/05/31 Javascript
关于Function中的bind()示例详解
2016/12/02 Javascript
AngulerJS学习之按需动态加载文件
2017/02/13 Javascript
微信小程序手势操作之单触摸点与多触摸点
2017/03/10 Javascript
vue.js的手脚架vue-cli项目搭建的步骤
2017/08/30 Javascript
Vue组件和Route的生命周期实例详解
2018/02/10 Javascript
node.js实现为PDF添加水印的示例代码
2018/12/05 Javascript
Vue 处理表单input单行文本框的实例代码
2019/05/09 Javascript
JS中如何轻松遍历对象属性的方式总结
2019/08/06 Javascript
vue 解决遍历对象显示的顺序不对问题
2019/11/07 Javascript
JavaScript复制变量三种方法实例详解
2020/01/09 Javascript
[01:13:51]TNC vs Serenity 2018国际邀请赛小组赛BO2 第二场 8.18
2018/08/19 DOTA
举例讲解Python中的身份运算符的使用方法
2015/10/13 Python
将pymysql获取到的数据类型是tuple转化为pandas方式
2020/05/15 Python
python中可以声明变量类型吗
2020/06/18 Python
利用Python pandas对Excel进行合并的方法示例
2020/11/04 Python
css3的transform中scale缩放详解
2014/12/08 HTML / CSS
详解HTML5中div和section以及article的区别
2015/07/14 HTML / CSS
英国花园药房: The Garden Pharmacy
2017/12/28 全球购物
美国鲍勃商店:Bob’s Stores
2018/07/22 全球购物
加大码胸罩、内裤和服装:Just My Size
2019/03/21 全球购物
abstract是什么意思
2012/02/12 面试题
EJB3推出JPA的原因
2013/10/16 面试题
幼儿园老师寄语
2014/04/03 职场文书
2015年建筑工作总结报告
2015/05/04 职场文书
2016年大学迎新晚会工作总结
2015/10/15 职场文书
MySQL详解进行JDBC编程与增删改查方法
2022/06/16 MySQL