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>    

enter image description here

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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -