LoginSignup
9
7

More than 5 years have passed since last update.

canvas要素のテキストの文字間を広げる

Last updated at Posted at 2016-09-05

スクリーンショット 2016-09-05 13.44.19.png
このテキストを広げてあげたい。

CSSのletter-spacingを当ててあげる

canvas要素にletter-spacingを当ててあげると
canvasで描画されたテキストにも適応される

スクリーンショット 2016-09-05 13.44.06.png
こんな感じに広がってくれます。

letter-spacingにアニメーションを当ててみる

CSS Animationでletter-spacingプロパティをいじってあげると動きます。
用途がかなり限られると思いますが…

dot_bbj.gif

また、js側でfontを指定してあげるのとcanvasを都度更新してあげないとCSS Animationは適応されませんでした…

function render(){
  stage.clear();
  c.textAlign = 'center';
  c.font = '24px "Fjalla One"'; // <= フォントの指定をしてあげないとCSS Animationが効きませんでした。
  c.fillStyle = '#59bb0c';
  c.fillText('HELLO Qiita',200,00);
  rendering = requestAnimationFrame(render);// あとcanvasの描画を更新も
}

正直使いどころがないと思いますが、ちょっと面白かったので記事を書いてみました。

9
7
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7