แคนวาส HTML5 ให้ความสามารถในการสร้างเงาที่สวยงามรอบๆ ภาพวาด การดำเนินการวาดทั้งหมดได้รับผลกระทบจากแอตทริบิวต์เงาทั้งสี่
| Sr.No. | คุณสมบัติและคำอธิบาย |
|---|---|
| 1 | shadowColor [ =ค่า ] คุณสมบัตินี้จะคืนค่าสีเงาปัจจุบันและสามารถตั้งค่าเพื่อเปลี่ยนสีเงาได้ |
| 2 | shadowOffsetX [ =ค่า ] คุณสมบัตินี้ส่งคืน Shadow offset X ปัจจุบันและสามารถตั้งค่าได้ เพื่อเปลี่ยน Shadow offset 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>