DIV CSS 佈局教程網

使用 Canvas 繪製空心文字效果
編輯:JavaScript綜合知識     

實作概念

Canvas 除了 fillText 可填滿文字外,也能使用 strokeText() 繪製只有外框的空心文字。這適合標題、海報或特殊視覺效果。

範例程式

const c = document.getElementById('myCanvas');
const ctx = c.getContext('2d');

ctx.font = '30px Arial';
ctx.strokeText('Hello World', 10, 50);

可調整項目

可透過 lineWidth 調整外框粗細,也可用 strokeStyle 設定線條顏色。若要同時有填色與外框,可先 fillText 再 strokeText。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved