Skip to content
本页目录

Canvas 状态

save() 保存当前环境的状态。

restore() 返回之前保存过的路径状态和属性。

js
context.fillStyle = 'red'
context.fillRect(0, 0, 100, 100)
context.save()

context.fillStyle = 'blue'
context.fillRect(100, 100, 100, 100)
context.save()

context.fillStyle = 'yellow'
context.fillRect(200, 200, 100, 100)
context.save()

context.fillStyle = 'green'
context.fillRect(300, 300, 100, 100)

context.restore()
context.fillRect(400, 400, 100, 100)

context.restore()
context.fillRect(500, 500, 100, 100)

lemon's personal blog.