HTML5畫布圓形文字


要在畫布上的圓內建立文字,請使用−

context.beginPath();

示例

以下是畫布−

$("#demo").on("click", "#canvas1", function(event) {
   var canvas = document.getElementById('canvas1');
      if (canvas.getContext) {
         var context = canvas.getContext("2d");
         var w = 25;
         var x = event.pageX;
         var y = Math.floor(event.pageY-$(this).offset().top);
         
         context.beginPath();
         context.fillStyle = "blue";
         context.arc(x, y, w/2, 0, 2 * Math.PI, false);
         context.fill();
         context = canvas.getContext("2d");
         context.font = '9pt';
         context.fillStyle = 'white';
         context.textAlign = 'center';
         context.fillText('amit', x, y+4);
      }
});

HTML

<div id = demo>
   <canvas id = canvas1></canvas>
</div>

更新於:2020年6月25日

422次瀏覽

開啟您的職業生涯

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.