0.0.1 • Published 3 years ago

react-scratch-perfect-ok v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

欢迎使用react刮一刮组件

此组件使用图片时未使用getImageData方法,没有跨域问题,使用简单,适合多场景使用

安装

 npm install react-scratch-perfect --save

例子: https://dsmelon.github.io/react-scratch-perfect/dist/index.html

api

参数名类型默认值说明
classNamestring容器的类名
clearbooleanfalse完成后是否清除画布
colorstring#808080刮刮卡的颜色
imgstring刮刮卡的填充图片(如果图片加载失败,会使用颜色值)
imgRepeatstring图片填充方式width: 宽度撑满,高度自适应并居中 height: 高度撑满,宽度自适应并居中 repeat: 重复填充无值会被拉伸铺满容器
sizenumber1/10容器宽度画笔直径
roundarray[number][0,0,0,0]奖品限定区域,分别为上右下左的padding值
percentagenumber70完成百分比(round之外的不参与计算)
modestringmove在什么时刻触发onChange和onSuccessmove: 手指移动时触发onChange和onSuccess end: 手指抬起时触发onChange和onSuccess
onChangefunction(percentage)改变时触发的函数,回传的是已经刮出的百分比
onSuccessfunction完成时的回调

使用方法

<Scratch
    color="#808080"
    img=""
    round={[100,50,100,50]}
    size={40}
    imgRepeat="height"
    percentage={70}
    clear={false}
    mode="move"
    onChange={this.handleChange}
    onSuccess={this.onSuccess}
    className="scratch"
>
    <div className="s1">一等奖</div>
</Scratch>
.s1{
    font-size: 100px;
    line-height: 320px;
    height: 320px;
    width: 450px;
    color: deeppink;
    display: inline-block;
}

github地址: https://github.com/dsmelon/react-scratch-perfect