javascript - html5 canvas behavior when canvas size is modified -
when modify html5 canvas size, , draw next text, aspect ratio of text skewed. not expect behavior. doing wrong?
<!doctype html> <html> <script src="jquery-ui/js/jquery-1.9.1.js"></script> <style> canvas{border:1px solid green} </style> <body> <canvas id="mycanvas" width="300" height="200"></canvas> <script> var canvas = document.getelementbyid('mycanvas'); var context = canvas.getcontext('2d'); var height=200; var myvar=setinterval(function(){repeat()},1000); function repeat(){ $('#mycanvas').css("height",height+=50); $('#mycanvas').css("width",300); // var canvas = document.getelementbyid('mycanvas'); // var context = canvas.getcontext('2d'); context.font = 'italic 40pt calibri'; context.filltext("super test", 40, 100); } </script>
using canvas.setattribute('height', h);
instead of $('#mycanvas').css("height",h);
...
<!doctype html> <html> <script src="jquery-ui/js/jquery-1.9.1.js"></script> <style> canvas{border:1px solid green} </style> <body> <canvas id="mycanvas" width="300" height="200"></canvas> <script> var canvas = document.getelementbyid('mycanvas'); var context = canvas.getcontext('2d'); var height=200; var myvar=setinterval(function(){repeat()},1000); function repeat(){ canvas.setattribute('height', height+=50); context.font = 'italic 40pt calibri'; context.filltext("super test", 40, 100); } </script>
Comments
Post a Comment