HTML5 캔버스는 그림 주위에 멋진 그림자를 만드는 기능을 제공합니다. 모든 그리기 작업은 4가지 전역 그림자 속성의 영향을 받습니다.
| Sr.No. | 속성 및 설명 |
|---|---|
| 1 | shadowColor [ =값 ] 이 속성은 현재 그림자 색상을 반환하고 그림자 색상을 변경하기 위해 설정할 수 있습니다. |
| 2 | shadowOffsetX [ =값 ] 이 속성은 현재 그림자 오프셋 X를 반환하고 설정하여 그림자 오프셋 X를 변경할 수 있습니다. |
| 3 | shadowOffsetY [ =값 ] 이 속성은 현재 그림자 오프셋 Y를 반환하고 설정하고 그림자 오프셋 Y를 변경할 수 있습니다. |
| 4 | shadowBlur [ =값 ] 이 속성은 그림자에 적용된 흐림의 현재 수준을 반환하고 설정하여 흐림 수준을 변경할 수 있습니다. |
예시
다음 코드를 실행하여 그림자를 만들 수 있습니다.
<!DOCTYPE HTML>
<html>
<head>
<style>
#test {
width: 100px;
height:100px;
margin: 0px auto;
}
</style>
<script type>
function drawShape(){
// get the canvas element using the DOM
var canvas = document.getElementById('mycanvas');
// Make sure we don't execute when canvas isn't supported
if (canvas.getContext){
// use getContext to use the canvas for drawing
var ctx = canvas.getContext('2d');
ctx.shadowOffsetX = 2;
ctx.shadowOffsetY = 2;
ctx.shadowBlur = 2;
ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
ctx.font = "20px Times New Roman";
ctx.fillStyle = "Black";
ctx.fillText("This is shadow test", 5, 30);
} else {
alert('You need Safari or Firefox 1.5+ to see this demo.');
}
}
</script>
</head>
<body id = "test" onload = "drawShape();">
<canvas id = "mycanvas"></canvas>
</body>
</html>