小程序畫布清除畫布上矩形區(qū)域內(nèi)的內(nèi)容CanvasContext.clearRect
CanvasContext.clearRect(number x, number y, number width, number height)
清除畫布上在該矩形區(qū)域內(nèi)的內(nèi)容
小程序插件:支持
參數(shù)
number x
矩形路徑左上角的橫坐標(biāo)
number y
矩形路徑左上角的縱坐標(biāo)
number width
矩形路徑的寬度
number height
矩形路徑的高度
示例代碼
clearRect 并非畫一個白色的矩形在地址區(qū)域,而是清空,為了有直觀感受,對 canvas 加了一層背景色。
<canvas canvas-id="myCanvas" style="border: 1px solid; background: #123456;"/>
const ctx = wx.createCanvasContext('myCanvas')
ctx.setFillStyle('red')
ctx.fillRect(0, 0, 150, 200)
ctx.setFillStyle('blue')
ctx.fillRect(150, 0, 150, 200)
ctx.clearRect(10, 10, 150, 75)
ctx.draw()
作者:大學(xué)生新聞網(wǎng) 來源:大學(xué)生新聞網(wǎng)