Open
Description
背景
最近在学习canvas
。准备写个刮刮乐练练手。
需求
- 基本的瓜瓜交互;
- 支持背景图片;
- 支持刮到指定大小区域时触发回调函数。
实现
var guaGuaLe = new GuaGuaLe('js-canvas', {
backgroundColor: 'red',
backgroundImage: '/asserts/star.png',
backgroundRepeat: 'repeat',
backgroundSize: '40',
backgroundPosition: 'center',
onWipeThreshold: ares => {
console.log(`wipe area ${ares}`)
document.getElementById('js-result').innerHTML = '中奖啦'
}
})
document.getElementById('js-refresh').addEventListener('click', () => {
document.getElementById('js-result').innerHTML = '...'
guaGuaLe.refresh();
})
其他option
如下,用法同canvas
API:
'globalCompositeOperation'
'globalAlpha'
'lineCap'
'lineWidth'
'lineJoin'
'miterLimit'
'shadowColor'
'shadowBlur'
'shadowOffsetX'
'shadowOffsetY'