Implementation of multi-grid lottery activities
Nowadays, WeChat mini programs are becoming more and more popular, and we are constantly sharing tutorials related to WeChat mini programs. In this article, we continue to share with you the multi-square lottery function of WeChat mini programs.
First look at the effect:
The idea is to let it rotate for more than 2 turns, and then draw a lottery. The grid movement uses setTimeout and let it run. The time intervals are different, and then the effect of the speed of movement is produced
Okay, the above code
The first is WXML (the judgment here may be a bit confusing, read it carefully in order, because the fifth There is a problem with the display of the first and eleventh grid on different mobile phone screen sizes, so I judged them again)
<view class="box"> <view class="boxsub {{luckynum==index?'luck':''}}" wx:for='{{box}}' style="{{index>0&&index<4?'top:0;left:'+index*140+'rpx;':(index>3&&index<8?'right:0; top:'+((index-4)*100)+'rpx;':(index>7&&index<12?'bottom:0;right:'+(index-7)*140+'rpx;':(index>11&&index<14?'left:0;bottom:'+(index-11)*100+'rpx;':'')))}} {{index=='4'?'top:0;':''}} {{index=='11'?'left:0;':''}} " wx:key=''> <text class='boxcontent' style='{{item.name.length>6?"line-height:40rpx;margin-top:10rpx;":"line-height:100rpx;"}}'>{{item.name}}</text> </view> <view class="lucky" catchtap="luckyTap"> <text class="taplucky">点击抽奖</text> <text class="howMany">您还有<text class="howMany_num" >{{howManyNum}}</text>次抽奖机会</text> </view> </view> <view class="explain"> </view>
WXSS:
.box{ margin:20rpx 25rpx; height: 400rpx; width: 698rpx; /*border:1px solid #ddd;*/ position: relative; /*box-sizing: border-box;*/ } .boxsub{ width: 140rpx; height: 100rpx; /*border: 1px solid #f00;*/ box-sizing: border-box; position: absolute; background: #ff6100; border: 1rpx solid #fff; } .boxcontent{ text-align: center; font-size: 26rpx; display: block; color: #fff; } .lucky{ width: 300rpx; height:130rpx; background:#ff6100;/* #ff6100;007FFF*/ position: absolute; left: 0; bottom: 0; right: 0; top: 0rpx; margin: auto; } .lucky:active{ opacity: 0.7; } .taplucky{ display: block; text-align: center; font-size: 30rpx; line-height: 50rpx; height: 50rpx; color: #fff; margin-top: 20rpx; } .howMany{ display: block; text-align: center; font-size: 26rpx; color: #fff; line-height: 40rpx; height: 40rpx; } .howMany_num{ color:#007FFF; font-size:32rpx; line-height:40rpx; padding:0 10rpx; } .luck{ opacity: 0.5; background: #ff6100; }
JS
##
var time = null;//setTimeout的ID,用clearTimeout清除 Page({ data: { box: [{ name:'100积分' }, { name: '10元优惠券\n满100可用' }, { name: '60积分' }, { name: '30积分' }, { name: '50积分' }, { name: '30元优惠券\n满120可用' }, { name: '100积分' }, { name: '200积分' }, { name: '10积分' }, { name: '50积分' }, { name: '40积分' }, { name: '50优惠券满500可用' }, { name: '60积分' }, { name: '70积分' }], luckynum:0,//当前运动到的位置,在界面渲染 howManyNum:10,//抽奖的剩余次数 content:{ index: 0, //当前转动到哪个位置,起点位置 count: 0, //总共有多少个位置 speed: 50, //初始转动速度 cycle: 3*14, //转动基本次数:即至少需要转动多少次再进入抽奖环节,这里设置的是转动三次后进入抽奖环节 }, prize:0,//中奖的位置 luckytapif:true//判断现在是否可以点击 }, //点击抽奖 luckyTap:function(){ var i=0, that=this, howManyNum = this.data.howManyNum,//剩余的抽奖次数 luckytapif = this.data.luckytapif,//获取现在处于的状态 luckynum = this.data.luckynum,//当前所在的格子 prize =Math.floor(Math.random()*14) ;//中奖序号,随机生成 if (luckytapif && howManyNum>0){//当没有处于抽奖状态且剩余的抽奖次数大于零,则可以进行抽奖 console.log('prize:'+prize); this.data.content.count=this.data.box.length; this.setData({ howManyNum:howManyNum-1//更新抽奖次数 }); this.data.luckytapif=false;//设置为抽奖状态 this.data.prize = prize;//中奖的序号 this.roll();//运行抽奖函数 } else if (howManyNum == 0 && luckytapif){ wx.showModal({ title: '', content: '您的抽奖次数已经没有了', showCancel:false }) } }, //抽奖 roll:function(){ var content=this.data.content, prize = this.data.prize,//中奖序号 that=this; if (content.cycle - (content.count-prize)>0){//最后一轮的时间进行抽奖 content.index++; content.cycle--; this.setData({ luckynum: content.index%14 //当前应该反映在界面上的位置 }); setTimeout(this.roll, content.speed);//继续运行抽奖函数 }else{ if (content.index < (content.count*3 + prize)){//判断是否停止 content.index++; content.speed += (550 /14);//最后一轮的速度,匀加速,最后停下时的速度为550+50 this.data.content=content; this.setData({ luckynum: content.index % 14 }); console.log(content.index, content.speed);//打印当前的步数和当前的速度 setTimeout(this.roll,content.speed); }else{ //完成抽奖,初始化数据 console.log('完成'); content.index =0; content.cycle = 3 * 14; content.speed = 50; this.data.luckytapif = true; clearTimeout(time); wx.showModal({ title: '', content: '恭喜你抽到了'+that.data.box[prize].name, showCancel:false }) } } }, onLoad: function (options) { }, onReady: function () { }, onShow: function () { }, onHide: function () { }, onUnload: function () { } })
How to implement the image enlargement preview function in the WeChat applet
WeChat applet-imitation Hema Xiansheng
The most complete WeChat Mini Program Project Example
The above is the detailed content of Implementation of multi-grid lottery activities. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

King of Glory has launched the Let’s Go Together to Flower Season event. Players who participate in the event can receive free avatar frames and many gifts. The event has a time limit and provides players with a total of four levels. Today, the editor has brought you a guide to the Let’s Go to Flower Season event. Encyclopedia, I hope it can help everyone complete the level challenge. A guide to the King of Glory's "Going to the Flowering Season" event. King of Glory, "Going to the Flowering Season" activity introduction. How to play: 1. "Going to the Flowering Season" is a card-turning activity, and players need to turn over the cards to pass the level. 2. Players can turn over cards by completing tasks and obtaining flower dew during the event. 3. Every four clearance cards in the activity panel are connected into a line (including horizontal lines, vertical lines and diagonal lines) to pass a small level. 4. Every time you clear a level, you can get corresponding rewards, and you can also get additional rewards by helping your friends turn over cards. live

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

Love and Deep Space has confirmed that it will be updated on March 1st to launch Qi Yu’s birthday theme event. Players can participate in the event to experience the exclusive birthday celebration plot. In addition, there are birthday-limited thoughts, daily clothing, 20 deep space wishing coupons and other rewards waiting for you. Continue Come down and follow the editor to see the details of this event. Qi Yu’s birthday theme event of Love and Deep Space is about to start: experience the exclusive birthday plot. Participate in the event and experience the exclusive birthday plot. There are also colorful rewards such as birthday-limited thoughts, daily clothing, and "Deep Space Wishing Vouchers·Limited Time*20" waiting for you! Event time: After the update on March 1st ~ 4:59 am on March 8th Exclusive Hug: Birthday five-star miss limited time UP wishing event During the limited-time five-star miss "Qi Yu·Adventures in this Life" wishing probability is greatly increased for a limited time. *After the event, this photo

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

In daily work, we encounter a lot of things that require drawing lots. The traditional method is to randomly draw numbers using paper numbers. With the development of electronic software, we can use computers to draw lots. The lesson I want to share with you today is How to make an excel lottery applet. 1. First, we open the Excel software and open the table we prepared. The table must contain our names. 2. Then we merge the cells on the right, fill in black who is lucky tonight, and merge the cells below and fill in red, as shown in the figure below. 3. Then we enter the randbetween function in the red area and set the first line to 2 and the last line to 7, as shown in the figure below. 4. Then we enter ind in front

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

As the D-Day invasion approaches its 80th anniversary, a whole month of World of Tanks events and specials will be centered around Operation Overlord - a new PvE mode, a themed battle pass, the release of a new Frontline mode, and a month-long The Operation Normandy token store is about to open. OPERATION MAP From June 3 to June 30, explore the beaches of Normandy and collect up to 90 Operation Normandy Tokens: 36 from this map and another 54 by completing daily tasks. Check out the interactive map and see the start dates for each event, then start earning tokens now, or unlock special token missions. Use the map to learn more about Operation Normandy related activities. Once you have obtained enough Operation Normandy tokens, you can go to the Operation Normandy token dealer

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.
