CanvasRenderingContext2D.restore()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Метод CanvasRenderingContext2D.restore()
восстанавливает предварительно сохранённое состояние канваса из стека. Если состояние ранее не сохранялось, то метод ничего не делает.
Fore more information about the drawing state, see CanvasRenderingContext2D.save()
.
Синтаксис
void ctx.restore();
Пример
Restoring a saved state
This example uses the save()
method to save the default state and restore()
to restore it later, so that you are able to draw a rect with the default state later.
HTML
<canvas id="canvas"></canvas>
JavaScript
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
// Save the default state
ctx.save();
ctx.fillStyle = "green";
ctx.fillRect(10, 10, 100, 100);
// Restore the default state
ctx.restore();
ctx.fillRect(150, 40, 100, 100);
Результат
Спецификации
Specification |
---|
HTML # dom-context-2d-restore-dev |
Совместимость с браузерами
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
restore |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
Смотрите также
- The interface defining this method:
CanvasRenderingContext2D
CanvasRenderingContext2D.save()