【发布时间】:2017-11-17 02:02:39
【问题描述】:
你能告诉我画布上的文字有什么问题吗?我试图改变文本大小,如果我把它变大它看起来不错,但如果我把它变小它看起来很奇怪。我不确定究竟是什么影响了文本;我尝试使用字体属性但没有结果,每当我将字体变小时,我都会得到类似于下面 sn-p 的结果 这是我的代码
(function(){
function init(){
var canvas = document.getElementsByTagName('canvas')[0];
var c = canvas.getContext('2d');
var animationStartTime =0;
c.fillStyle = 'white';
c.font = 'normal 10pt';
var textarray = 'you can live a beatiful life with a postive mind';
var j=1;
//time - next repaint time - HRT
function draw(time){
c.fillText(textarray.substr(0,j),10,70);
if(time - animationStartTime > 100){
animationStartTime = time;
j++;
}
if( j <= textarray.length){
requestAnimationFrame(draw); // 17ms
}
}
function start(){
animationStartTime = window.performance.now();
requestAnimationFrame(draw);
}
start();
}
//invoke function init once document is fully loaded
window.addEventListener('load',init,false);
}()); //self invoking function
#canvas{
overflow:hidden;
background-image: url('http://linux2.gps.stthomas.edu/~algh3635/practice/proj/img/img4.jpeg');
background-repeat: no-repeat;
background-size: cover;
}
canvas {
width:100%;
height:80vh;
left: 0;
margin: 0;
padding: 0;
position: relative;
top: 0;
}
<div id="canvas">
<div class="row">
<div class="col-lg-12 text-center" >
<canvas >
</canvas>
</div>
</div>
</div>
【问题讨论】:
标签: javascript html canvas text