CanvasRenderingContext2D
.globalCompositeOperation
property of the Canvas 2D API sets the type of compositing operation to apply when drawing new shapes.
另请参阅 Compositing and clipping 在 Canvas Tutorial .
ctx.globalCompositeOperation = type;
type
是
字符串
identifying which of the compositing or blending mode operations to use.
此范例使用
globalCompositeOperation
property to draw two rectangles that exclude themselves where they overlap.
<canvas id="canvas"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.globalCompositeOperation = 'xor';
ctx.fillStyle = 'blue';
ctx.fillRect(10, 10, 100, 100);
ctx.fillStyle = 'red';
ctx.fillRect(50, 50, 100, 100);
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'CanvasRenderingContext2D.globalCompositeOperation' in that specification. |
实时标准 | |
| Compositing and Blending Level 1 | 候选推荐 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
globalCompositeOperation
|
Chrome 1 | Edge 12 | Firefox 1.5 | IE 9 | Opera 9 | Safari 2 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 |
完整支持
ctx.setCompositeOperation()
is implemented besides this property.
"plus-darker"
and
"darker"
were removed in Chrome 48. Developers looking for a replacement should use
"darken"
.
"darker"
. However, Firefox removed support for
"darker"
in version 4 (
bug 571532
)。另请参阅
this blog post
that suggests using
"difference"
as a way to achieve a similar affect to
"darker"
.
CanvasRenderingContext2D
CanvasRenderingContext2D.globalAlpha
CanvasRenderingContext2D
addHitRegion()
arc()
arcTo()
beginPath()
bezierCurveTo()
clearHitRegions()
clearRect()
clip()
closePath()
createImageData()
createLinearGradient()
createPattern()
createRadialGradient()
drawFocusIfNeeded()
drawImage()
drawWidgetAsOnScreen()
drawWindow()
ellipse()
fill()
fillRect()
fillText()
getImageData()
getLineDash()
getTransform()
isPointInPath()
isPointInStroke()
lineTo()
measureText()
moveTo()
putImageData()
quadraticCurveTo()
rect()
removeHitRegion()
resetTransform()
restore()
rotate()
save()
scale()
scrollPathIntoView()
setLineDash()
setTransform()
stroke()
strokeRect()
strokeText()
transform()
translate()