canvas使用自定义字体没有效果

字体样式没有显示主要是因为字体还没有加载完成~

css

@font-face {
font-family: myFont;
src: local('sen.ttf'), url("sen.ttf");
}

html

<canvas id="can" width="300px" height="300px"></canvas>

js

window.onload = function () {
let el = document.getElementById('can');
let ctx = el.getContext('2d');
ctx.font = '20px myFont';
ctx.fillText('你好啊啊啊啊', 20, 20);
};

posted @ 2018-08-14 21:58  刘倩文  阅读(1113)  评论(0编辑  收藏  举报