只需引入canvas.js
<script src="./js/canvas.js"></script>
html
<canvas id="canvas"></canvas> 重置按钮,固定ID <div id="freshBtn">重置</div> 样式可自行设计
js
//创建实例 var canvas = new canvasInit({ id: canvas标签的ID, cover: 覆盖层( 可填颜色 / 图片路径), coverType: 依赖上一选项(可填 'color' / 'image'), width: canvas宽度(默认单位px), height: canvas高度(默认单位px), drawPercentCallback: function(num) { 回调函数, 可为空 返回已抹去元素的百分比 例如: if (num > 30) { alert('获得一等奖') canvas.fresh() // 提供的重置方法 } } })
在移动端报错了:
[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See <URL>回复