亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    微信小程序刮刮卡的實現(xiàn)

    微信小程序刮刮卡的實現(xiàn)

    如何實現(xiàn)刮刮卡的效果呢?

    思路是:

    1、先將中獎的圖片或者文字位置和大小確定

    2、開始畫canvas,將位置和大小跟之前中獎的文案的位置保持一致。

    3、在canvas上覆蓋一層灰色的蒙層,作出刮刮卡未刮之前的效果

    具體代碼如下

    let left=0; this.data.awardCanvas.moveTo(left,0) this.data.awardCanvas.lineTo(left+400,0); this.data.awardCanvas.lineTo(left+400,150); this.data.awardCanvas.lineTo(left,150); this.data.awardCanvas.stroke() this.data.awardCanvas.setFillStyle('#ddd') this.data.awardCanvas.fill() this.data.awardCanvas.draw()

    4、開始做刮刮卡的動作,在canvas定義bindtouchstart和bindtouchmove兩個觸發(fā)的動作

    bindtouchstart是開始落手指的第一個位置,bindtouchmove是手指移動的位置

    其中重要一個canvas屬性是clearRect,清除畫布上的內(nèi)容

    clearRect(清除位置的X坐標,清除位置的Y坐標,清除的寬度,清除的高度)

    具體代碼如下:

    this.data.awardCanvas.clearRect(x,y,15,15); this.data.awardCanvas.draw(true)

    具體的代碼在https://github.com/zhaodengping/scratch-mini

    快去試試吧,也許能刮到一等獎哦~~

    推薦教程:《微信小程序》

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號