Build a Configurable Canvas Lottery Wheel in WeChat Mini Programs – Step‑by‑Step Guide

This tutorial walks you through creating a configurable lottery wheel using Canvas in a WeChat Mini Program, covering the overall concept, required WXML layout, animation setup, interactive button handling, and how to display prize rules, with a complete code example.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Build a Configurable Canvas Lottery Wheel in WeChat Mini Programs – Step‑by‑Step Guide

Overview

Today we share a practical WeChat Mini Program case: a Canvas‑drawn, configurable lottery wheel. The tutorial provides a concise guide to help developers implement this feature in their own mini‑apps.

Demo Image

Example Files

<view class="wrapper">
    <view class="header">
        <text class="header-title">大转盘抽奖</text>
        <text class="header-subtitle">感恩节活动大抽奖,反馈广大客户</text>
    </view>
    <view class="main">
        <view class="canvas-container">
            <view animation="{{animationData}}" class="canvas-content">
                <canvas style="width:300px;height:300px;" class="canvas-element" canvas-id="lotteryCanvas"></canvas>
                <view class="canvas-line">
                    <view class="canvas-litem" wx:for="{{awardsList}}" wx:key="unique" style="-webkit-transform:rotate({{item.lineTurn}});transform:rotate({{item.lineTurn}})"></view>
                </view>
                <view class="canvas-list">
                    <view class="canvas-item" wx:for="{{awardsList}}" wx:key="unique">
                        <view class="canvas-item-text" style="-webkit-transform:rotate({{item.turn}});transform:rotate({{item.turn}})">{{item.award}}</view>
                    </view>
                </view>
            </view>
            <view bindtap="getLottery" class="canvas-btn {{btnDisabled}}">抽奖</view>
        </view>
        <view class="main-container">
            <view class="main-container-btn">
                <button bindtap="gotoList" type="primary">查看中奖</button>
            </view>
            <view class="main-container-rule">
                <text class="main-rule-title">活动规则:</text>
                <text class="main-rule-item">1. xxxxxxxxxxx</text>
                <text class="main-rule-item">2. xxxxxxxxxxx</text>
                <text class="main-rule-item">3. xxxxxxxxxxx</text>
                <text class="main-rule-item">4. xxxxxxxxxxx</text>
                <text class="main-rule-item">5. xxxxxxxxxxx</text>
            </view>
        </view>
    </view>
</view>

If you encounter issues retrieving the code or need further assistance, you can contact the author via WeChat (ID: geekxz).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaScriptfrontend developmentCanvasWeChat Mini ProgramWXMLLottery Wheel
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.