亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

代碼
提交代碼
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>慕課網Wiki</title> <style> #imooc{ border:1px solid #ccc; } </style> </head> <body> <canvas id="imooc">您的瀏覽器不支持 HTML5 canvas 標簽</canvas> <script> const canvas = document.getElementById('imooc'); canvas.width=360; canvas.height=130; const ctx = canvas.getContext('2d'); // 繪制第一個矩形 ctx.fillStyle="red" ctx.shadowBlur=2; ctx.shadowOffsetX=4; ctx.shadowOffsetY=4; ctx.shadowColor="#ccc" ctx.save(); // 這里把當前畫布的屬性做了一個標記,我們稱為:標記一 ctx.fillRect(40,40, 40,40) // 繪制第二個矩形 ctx.fillStyle="yellow" ctx.shadowBlur=3; ctx.shadowOffsetX=8; ctx.shadowOffsetY=8; ctx.shadowColor="#456795" ctx.save(); // 這里把當前畫布的屬性做了第二個標記,我們稱為:標記二 ctx.fillRect(100,40, 40,40) // 繪制第三個矩形 ctx.fillStyle="blue" ctx.shadowBlur=5; ctx.shadowOffsetX=5; ctx.shadowOffsetY=5; ctx.shadowColor="#222" ctx.fillRect(160,40, 40,40) // 繪制第四個矩形 ctx.restore() // 這里我們讀取了最新的一個標記,也就是讀區了標記二的狀態,標記二被讀取后就消失了。 ctx.fillRect(220,40, 40,40) // 繪制第五個矩形 ctx.restore(); // 這里我們讀取了最新的一個標記,也就是讀區了標記一的狀態,因為標記二已經消失了 ctx.fillRect(280,40, 40,40) </script> <body> </html>
運行結果