キャンバス上のテキストの問題点を教えてください。大きめにすると文字サイズを変えようとしましたが、小さくすると変わって見えます。テキストにどのような影響があるのかよく分かりません。あなたは上fillTextときに私のコードですキャンバス要素にテキストを描画する
(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; \t
}
\t
<div id="canvas">
<div class="row">
<div class="col-lg-12 text-center" >
\t \t \t \t \t \t <canvas >
\t \t \t \t \t \t
\t \t \t \t \t \t </canvas>
</div>
</div> \t \t \t
</div>
それは働いている、しかし、私が望んでいたことはテキストを描画してアニメーション化するキャンバスのプロパティを使用しています。ありがとうございます – Ahmed
@Ahmedなぜですか?何らかの理由?ほとんどのWeb開発者はキャンバスを使用しません – Jesus
それはちょうど割り当ての要件です:) – Ahmed