中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

HTML5 Canvas陰影用法演示

發布時間:2020-07-20 22:24:19 來源:網絡 閱讀:298 作者:gloomyfish 欄目:移動開發

HTML5 Canvas陰影用法演示

HTML5 Canvas中提供了設置陰影的四個屬性值分別為:

context.shadowColor = “red” 表示設置陰影顏色為紅色

context.shadowOffsetX = 0表示陰影相對TEXT的水平距離,0表示兩者水平位置重合

context.shadowOffsetY = 0表示陰影相對TEXT的垂直距離,0表示兩者垂直位置重合

context.shadowBlur = 10 陰影模糊效果,值越大模糊越厲害。

一個最簡單的帶有陰影的矩形代碼如下:

context.shadowColor = "RGBA(127,127,127,1)";

context.shadowOffsetX = 3;

context.shadowOffsetY = 3;

context.shadowBlur = 0;

context.fillStyle = "RGBA(0, 0, 0, 0.8)";  

context.fillRect(10, hh+10, 200,canvas.height/4-20);

效果如下:

HTML5 Canvas陰影用法演示

陰影文字:

只要設置shadowOffsetX與shadowOffsetY的值,當值都正數時,陰影相對文字的右下

方偏移。當值都為負數時,陰影相對文字的左上方偏移。

3D拉影效果:

在同一位置不斷的重復繪制文字同時改變shadowOffsetX、shadowOffsetY、shadowBlur

的值,從小到大不斷偏移不斷增加,透明度也不斷增加。就得到了拉影效果文字。

邊緣模糊效果文字:

在3D拉影效果的基礎上在四個方向重復,就得到了邊緣羽化的文字效果。

運行效果:

HTML5 Canvas陰影用法演示

程序代碼:

<!DOCTYPE html> <html> <head> <meta http-equiv="X-UA-Compatible" content="chrome=IE8"> <meta http-equiv="Content-type" content="text/html;charset=UTF-8"> <title>Canvas Clip Demo</title> <link href="default.css" rel="stylesheet" /> 	<script> 		var ctx = null; // global variable 2d context 		var imageTexture = null; 		window.onload = function() { 			var canvas = document.getElementById("text_canvas"); 			console.log(canvas.parentNode.clientWidth); 			canvas.width = canvas.parentNode.clientWidth; 			canvas.height = canvas.parentNode.clientHeight; 			 			if (!canvas.getContext) { 			    console.log("Canvas not supported. Please install a HTML5 compatible browser."); 			    return; 			} 			var context = canvas.getContext('2d'); 			 			// section one - shadow and blur 			context.fillStyle="black"; 			context.fillRect(0, 0, canvas.width, canvas.height/4); 			context.font = '60pt Calibri'; 			 			context.shadowColor = "white"; 			context.shadowOffsetX = 0; 			context.shadowOffsetY = 0; 			context.shadowBlur = 20; 			context.fillText("Blur Canvas", 40, 80); 			context.strokeStyle = "RGBA(0, 255, 0, 1)"; 			context.lineWidth = 2; 			context.strokeText("Blur Canvas", 40, 80); 			 			// section two - shadow font 			var hh = canvas.height/4; 			context.fillStyle="white"; 			context.fillRect(0, hh, canvas.width, canvas.height/4); 			context.font = '60pt Calibri'; 			 			context.shadowColor = "RGBA(127,127,127,1)"; 			context.shadowOffsetX = 3; 			context.shadowOffsetY = 3; 			context.shadowBlur = 0; 			context.fillStyle = "RGBA(0, 0, 0, 0.8)"; 			context.fillText("Blur Canvas", 40, 80+hh); 			 			// section three - down shadow effect 			var hh = canvas.height/4 + hh; 			context.fillStyle="black"; 			context.fillRect(0, hh, canvas.width, canvas.height/4); 			for(var i = 0; i < 10; i++) 			{ 				context.shadowColor = "RGBA(255, 255, 255," + ((10-i)/10) + ")"; 				context.shadowOffsetX = i*2; 				context.shadowOffsetY = i*2; 				context.shadowBlur = i*2; 				context.fillStyle = "RGBA(127, 127, 127, 1)"; 				context.fillText("Blur Canvas", 40, 80+hh); 			} 			 			// section four -  fade effect 			var hh = canvas.height/4 + hh; 			context.fillStyle="green"; 			context.fillRect(0, hh, canvas.width, canvas.height/4); 			for(var i = 0; i < 10; i++) 			{ 				context.shadowColor = "RGBA(255, 255, 255," + ((10-i)/10) + ")"; 				context.shadowOffsetX = 0; 				context.shadowOffsetY = -i*2; 				context.shadowBlur = i*2; 				context.fillStyle = "RGBA(127, 127, 127, 1)"; 				context.fillText("Blur Canvas", 40, 80+hh); 			} 			for(var i = 0; i < 10; i++) 			{ 				context.shadowColor = "RGBA(255, 255, 255," + ((10-i)/10) + ")"; 				context.shadowOffsetX = 0; 				context.shadowOffsetY = i*2; 				context.shadowBlur = i*2; 				context.fillStyle = "RGBA(127, 127, 127, 1)"; 				context.fillText("Blur Canvas", 40, 80+hh); 			} 			for(var i = 0; i < 10; i++) 			{ 				context.shadowColor = "RGBA(255, 255, 255," + ((10-i)/10) + ")"; 				context.shadowOffsetX = i*2; 				context.shadowOffsetY = 0; 				context.shadowBlur = i*2; 				context.fillStyle = "RGBA(127, 127, 127, 1)"; 				context.fillText("Blur Canvas", 40, 80+hh); 			} 			for(var i = 0; i < 10; i++) 			{ 				context.shadowColor = "RGBA(255, 255, 255," + ((10-i)/10) + ")"; 				context.shadowOffsetX = -i*2; 				context.shadowOffsetY = 0; 				context.shadowBlur = i*2; 				context.fillStyle = "RGBA(127, 127, 127, 1)"; 				context.fillText("Blur Canvas", 40, 80+hh); 			} 		} 		 	</script> </head> <body> 	<h2>HTML5 Canvas Clip Demo - By Gloomy Fish</h2> 	<pre>Fill And Stroke Clip</pre> 	<div id="my_painter"> 		<canvas id="text_canvas"></canvas> 	</div> </body> </html>
轉載請注明

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

团风县| 宁波市| 天全县| 蒙城县| 图们市| 铜梁县| 巴东县| 安吉县| 青阳县| 怀来县| 武隆县| 建湖县| 沿河| 鹤壁市| 萝北县| 墨竹工卡县| 武陟县| 万荣县| 孟津县| 黑山县| 红安县| 甘泉县| 江华| 托克托县| 临夏县| 宕昌县| 深圳市| 和静县| 贡嘎县| 西藏| 西乡县| 宁陕县| 德格县| 扎囊县| 苍梧县| 漾濞| 黄浦区| 东丽区| 米泉市| 蒲江县| 锦州市|