javascript variables - html5 canvas issue -
in following code, change html canvas 5 font passing string. in second case use array , variables. first case works. second case not change fonts. problem in way construct variable.
<!doctype html> <html> <body> <canvas id="mycanvas" width="800" height="600"></canvas> <script> // array of fonts var fontarray = new array(); fontarray.push("antiqua"); fontarray.push("arial"); fontarray.push("comic sans"); var canvas = document.getelementbyid('mycanvas'); var context = canvas.getcontext('2d'); // works context.font = "25pt arial"; context.filltext('this works ', 30, 30); context.font = "25pt monospace"; context.filltext('this works ', 30, 80); // works shows no varaition of font for(x=0;x<3;x++){ var fonttext = "\'" + "20pt " + fontarray[x] + "\'" ; context.font = fonttext; console.log(fonttext); // print console context.filltext('this works shows no variation of font', 120, 140+(x*50)); } </script>
what if change:
var fonttext = "\'" + "20pt " + fontarray[x] + "\'" ;
to
var fonttext = "20pt " + fontarray[x];
Comments
Post a Comment