<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>canvas裁剪區域</title> <script src="js/modernizr.js"></script> </head> <body> <script type="text/javascript"> window.addEventListener('load',eventWindowLoaded,false); function eventWindowLoaded(){ canvasApp(); } function canvasSupport(){ return Modernizr.canvas; } function canvasApp(){ if(!canvasSupport()){ return; }else{ var theCanvas = document.getElementById('canvas') var context = theCanvas.getContext("2d") } drawScreen(); function drawScreen(){ context.fillStyle = "green"; context.fillRect(10,10,200,200); context.save(); context.beginPath(); context.rect(0,0,50,50); context.clip(); //紅色圓 context.beginPath(); context.strokeStyle="red"; context.lineWidth=5; context.arc(100,100,100,(Math.PI/180)*0,(Math.PI/180)*360,false); //整理 context.stroke(); context.closePath(); context.restore(); //再次裁剪整個畫布 context.beginPath(); context.rect(0,0,200,200); context.clip(); //繪製一個沒有裁剪的藍線 context.beginPath(); context.strokeStyle="blue"; context.lineWidth=5; context.arc(100,100,50,(Math.PI/180)*0,(Math.PI/180)*360,false); //整圓 context.stroke(); context.closePath(); } } </script> <canvas id="canvas" width="500" height="500"> 你的瀏覽器沒法使用canvas 若有問題,請在下方發送你問題,我看到會解答!! </canvas> </body> </html>
首先有個200*200的矩形是綠色的javascript
而後裁剪50*50.。下面那個圓弧只有50*50的區域內了html
而後再切換回200*200java
而後那個藍色的圓又看到了面試
大概的意思就是這樣canvas
最近忙着面試啥的搞得沒時間把個人canvas整理一下!瀏覽器
如今開始繼續整理!!!ui