It is provided in the form of WeChat components. Because async/await is used inside the component, please check "Enhance compilation and use npm" in the WeChat developer tool "Details = > Local settings". For the use of npm in the mini program, please refer to: WeChat Mini Program - npm support First look at the effect diagram:Steps:Step 1: Install dependencies or go to githua to download the source code and copy the lottery-turntable directory under the dist directory npm i lottery-turntable-for-wx-miniprogram Step 2: Page JSON configuration { "usingComponents": { "lottery-turntable":"lottery-turntable-for-wx-miniprogram/lottery_turntable/index" } } Step 3: Prepare data and add event handling (using component page JS) const datas = [{ "id": "792085712309854208", "imgUrl": "../../images/icon.png", "title": "Thunder Platinum Member Monthly Card - 1" }, { "id": "766410261029724160", "imgUrl": "../../images/icon.png", "title": "Thunder Platinum Member Monthly Card - 2" }, { "id": "770719340921364480", "imgUrl": "../../images/icon.png", "title": "Thunder Platinum Member Monthly Card - 3" }, { "id": "770946438416048128", "imgUrl": "../../images/icon.png", "title": "Thunder Platinum Member Monthly Card - 4" }, { "id": "781950121802735616", "imgUrl": "../../images/icon.png", "title": "Thunder Platinum Member Monthly Card - 5" }, { "id": "766411654436233216", "imgUrl": "../../images/icon.png", "title": "Thunder Platinum Member Monthly Card - 6" }, { "id": "770716883860332544", "imgUrl": "../../images/icon.png", "title": "Thunder Platinum Member Monthly Card - 7" }, { "id": "796879308510732288", "imgUrl": "../../images/icon.png", "title": "Thunder Platinum Member Monthly Card - 8" }]; Page({ data: { datas: datas, // data prizeId: '', // The winning result id is passed to the component through attributes config: { // Turntable configuration is passed to the component through attributes titleLength: 7 } }, /** * Insufficient times callback* @param e */ onNotEnoughHandle(e) { wx.showToast({ icon: 'none', title: e.detail }) }, /** * Lottery callback*/ onLuckDrawHandle() { this.setData({ prizeId: this.data.datas[Math.floor(Math.random() * 10 % this.data.datas.length)].id }); }, /** * Animation rotation completion callback */ onLuckDrawFinishHandle() { const datas = this.data.datas; const data = datas.find((item) => { return item.id === this.data.prizeId; }); wx.showToast({ icon: 'none', title: `Congratulations on winning ${data.title}` }) this.setData({ prizeId: '' }); } }) Step 4: Page Usage <lottery-turntable data="{{datas}}" prize-id="{{prizeId}}" count="{{5}}" config="{{config}}" bindLuckDraw="onLuckDrawHandle" bindNotEnough="onNotEnoughHandle" bindLuckDrawFinish="onLuckDrawFinishHandle" ></lottery-turntable> Step 5: Change the component configuration item (the following is the default configuration) and pass in a js object through the config attribute /** * ease: The values are as follows* 'linear' The speed of the animation is the same from beginning to end* 'ease' The animation starts at a slow speed, then speeds up, and slows down before the end* 'ease-in' The animation starts at a slow speed* 'ease-in-out' The animation starts and ends at a slow speed* 'ease-out' The animation ends at a slow speed* 'step-start' The animation jumps to the end state in the first frame and continues to end* 'step-end' The animation remains in the start state and jumps to the end state in the last frame*/ // The following is the default configuration let config = { size: { width: '572rpx', height: '572rpx' }, // Turntable width and heightbgColors: ['#FFC53F', '#FFED97'], // The background color of the turntable interval supports multiple color alternationfontSize: 10, // Text sizefontColor: '#C31A34', // Text colortitleMarginTop: 12, // Outermost text margintitleLength: 6 // Outermost text numbericonWidth: 29.5, // Icon widthiconHeight: 29.5, // Icon heighticonAndTextPadding: 4, // The margin between the innermost text and iconduration: 8000, // Turntable rotation animation durationrate: 1.5, // Obtained by duration s / number of circlesborder: 'border: 10rpx solid #FEFAE4;', // Turntable borderease: 'ease-out' // Turntable animation}; SummarizeThis is the end of this article about the WeChat Mini Program lottery component. For more relevant WeChat Mini Program lottery component content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of data type issues in JS array index detection
>>: Detailed explanation of uniapp's global variable implementation
This article records the installation graphic tut...
The key is that the local server does not have wr...
MySQL 8.0.25 decompression version installation t...
Recently, there is a need to automatically search...
Table of contents Experimental environment Instal...
I believe everyone is familiar with the trashcan,...
<br />Forms are an important channel for use...
Table of contents Breaking down components Left P...
Using padding-top percentage can achieve a fixed ...
When the scroll bar is pulled down, the floating ...
transform:scale() can achieve proportional zoomin...
Preface Linux's file permission management is...
Give time time and let the past go. In the previo...
Table of contents 1. Retrieve via --skip-grant-ta...
<br />Question: Why is it not recommended to...