Skip to content

ScratchCard

A canvas-based scratch card component. Users scratch off a top coating layer to reveal the prize content underneath. Supports custom coating colors/text, brush size, and auto-reveal on threshold. Ideal for marketing campaigns, lotteries, red packets, and other interactive scenarios.

Platform Differences

App (vue)App (nvue)H5Mini Program

Basic Usage

  • Place the prize content in the default slot. Set coverText for hint text on the coating.
  • The component automatically handles touch-scratch trails and reveals when the threshold (default 60%) is reached.
html
<see-scratch-card :width="300" :height="160" cover-text="Scratch here">
  <view class="prize">🎉 You won a ¥10 red packet!</view>
</see-scratch-card>

Custom Coating Color

  • Use coverColor for the coating background and coverTextColor for the text color.
html
<see-scratch-card :width="300" :height="160" cover-color="#ff6b6b" cover-text="Scratch & win" cover-text-color="#fff">
  <view>🎁 50 Points</view>
</see-scratch-card>

Gold Coating + Custom Threshold

  • Set brushSize for scratch brush radius and threshold for the auto-reveal percentage.
html
<see-scratch-card
  :width="300"
  :height="160"
  cover-color="#e8b830"
  cover-text="Scratch here"
  :brush-size="30"
  :threshold="40"
>
  <view>🏆 Free Order Coupon x1</view>
</see-scratch-card>

Disabled Mode

  • Set isDisabled to true to prevent scratching.
html
<see-scratch-card :width="300" :height="160" is-disabled cover-text="Scratch here">
  <view>Expired</view>
</see-scratch-card>

Events

  • onStart — fires on the first scratch (once per session).
  • onProgress — fires as scratch progress changes (percentage).
  • onComplete — fires when threshold is reached and autoReveal is true.
html
<see-scratch-card
  @on-start="onStart"
  @on-progress="onProgress"
  @on-complete="onComplete"
>
  <view>Prize content</view>
</see-scratch-card>

<script lang="ts" setup>
const onStart = () => console.log('Scratch started')
const onProgress = (percent: number) => console.log('Progress', percent, '%')
const onComplete = (percent: number) => console.log('Revealed', percent, '%')
</script>

API

Props

PropDescriptionTypeDefault
widthWidth (number = rpx)number | string600
heightHeight (number = rpx)number | string300
coverColorCoating solid colorstring'#c0c0c0'
coverImageCoating image URL (overrides coverColor)string''
coverTextCoating textstring'Scratch here'
coverTextColorCoating text colorstring'#ffffff'
coverTextSizeCoating text font size (rpx)number40
brushSizeScratch brush radius (rpx)number40
thresholdReveal threshold percentage (0-100)number60
isDisabledDisabledbooleanfalse
autoRevealAuto-reveal on thresholdbooleantrue
canvasIdCanvas ID (unique when multiple instances)stringauto-generated

Events

EventDescriptionPayload
onStartFirst scratch started-
onProgressScratch progress changedpercent: number
onCompleteThreshold reachedpercent: number

Expose

MethodDescriptionParams
revealManually reveal (clear all coating)-
resetReset coating (start over)-
getProgressGet current scratch percentage-

Slots

NameDescription
defaultPrize content (hidden under the coating)

Liao ICP No. 2025070134