HTML5에서 캔버스 그림자 효과 구현 코드 복사코드는 다음과 같습니다. 캔버스 클립 데모< ;link href="default.css" rel="stylesheet" /> <br> var ctx = null; // 전역 변수 2d context<br> var imageTexture = null;<br> window.onload = function() {<br> var canvas = document.getElementById("text_canvas");<br> console.log(canvas.parentNode .clientWidth);<br> canvas.width = canvas.parentNode.clientWidth;<br> canvas.height = canvas.parentNode.clientHeight;<br> <br> if (!canvas.getContext) {<br> console.log ("캔버스는 지원되지 않습니다. HTML5 호환 브라우저를 설치하세요.");<br> return;<br> }<br> var context = canvas.getContext('2d');<br> <br> // 섹션 1 - 그림자 및 흐림<br> context.fillStyle="black";<br> context.fillRect(0, 0, canvas.width, canvas.height/4);<br> context.font = '60pt Calibri';<br> <br> context.shadowColor = "white";<br> context.shadowOffsetX = 0;<br> context.shadowOffsetY = 0;<br> context.shadowBlur = 20;<br> context.fillText("흐림 캔버스 ", 40, 80);<br> context.StrokeStyle = "RGBA(0, 255, 0, 1)";<br> context.lineWidth = 2;<br> context.StrokeText("흐리게 캔버스", 40, 80);<br> <br> // 섹션 2 - 그림자 글꼴<br> var hh = canvas.height/4;<br> context.fillStyle="white";<br> context.fillRect(0, hh, canvas.width, canvas.height/4);<br> context.font = '60pt Calibri';<br> <br> context.shadowColor = "RGBA(127,127,127,1)";<br> context.shadowOffsetX = 3 ;<br> context.shadowOffsetY = 3;<br> context.shadowBlur = 0;<br> context.fillStyle = "RGBA(0, 0, 0, 0.8)";<br> context.fillText("흐리게 캔버스" , 40, 80 hh);<br> <br> // 섹션 3 - 아래쪽 그림자 효과<br> var hh = canvas.height/4 hh;<br> context.fillStyle="black";<br> context. fillRect(0, hh, canvas.width, canvas.height/4);<br> for(var i = 0; 나는 < 10; i )<br /> {<br /> context.shadowColor = "RGBA(255, 255, 255," ((10-i)/10) ")";<br /> context.shadowOffsetX = i*2;<br /> context.shadowOffsetY = i*2;<br /> context.shadowBlur = i*2;<br /> context.fillStyle = "RGBA(127, 127, 127, 1)";<br /> context.fillText("흐림 캔버스" , 40, 80 hh);<br /> }<br /> <br /> // 섹션 4 - 페이드 효과<br /> var hh = canvas.height/4 hh;<br /> context.fillStyle="green";<br /> context.fillRect(0, hh, canvas.width, canvas.height/4);<br /> for(var i = 0; i < 10; i )<br /> {<br /> context.shadowColor = "RGBA (255, 255, 255," ((10-i)/10) ")";<br /> context.shadowOffsetX = 0;<br /> context.shadowOffsetY = -i*2;<br /> context.shadowBlur = i *2;<br /> context.fillStyle = "RGBA(127, 127, 127, 1)";<br /> context.fillText("흐림 캔버스", 40, 80 hh);<br /> }<br /> for( var 나는 = 0; 나는 < 10; i )<br /> {<br /> context.shadowColor = "RGBA(255, 255, 255," ((10-i)/10) ")";<br /> context.shadowOffsetX = 0;<br /> 컨텍스트. ShadowOffsetY = i*2;<br /> context.shadowBlur = i*2;<br /> context.fillStyle = "RGBA(127, 127, 127, 1)";<br /> context.fillText("흐림 캔버스", 40 , 80 hh);<br /> }<br /> for(var i = 0; i < 10; i )<br /> {<br /> context.shadowColor = "RGBA(255, 255, 255," ((10 -i)/10) ")";<br /> context.shadowOffsetX = i*2;<br /> context.shadowOffsetY = 0;<br /> context.shadowBlur = i*2;<br /> context.fillStyle = "RGBA (127, 127, 127, 1)";<br /> context.fillText("흐림 캔버스", 40, 80 hh);<br /> }<br /> for(var i = 0; i < 10; i ) <br /> {<br /> context.shadowColor = "RGBA(255, 255, 255," ((10-i)/10) ")";<br /> context.shadowOffsetX = -i*2;<br /> context .shadowOffsetY = 0;<br /> context.shadowBlur = i*2;<br />context.fillStyle = "RGBA(127, 127, 127, 1)";<br /> context.fillText("흐림 캔버스", 40, 80 hh);<br /> }<br /> }<br /> <br /> < ;/script><br></head><br><body><br> <h1>HTML5 캔버스</h1><br> <pre>채우기 및 획 클립</pre><br> <div id="my_painter"><br> <canvas id="text_canvas"></canvas><br> </div><br></body><br></ html><br> </div>