Skip to content

Instantly share code, notes, and snippets.

@yogesh061
Created June 24, 2012 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yogesh061/2983915 to your computer and use it in GitHub Desktop.
Save yogesh061/2983915 to your computer and use it in GitHub Desktop.
Canvas resize drawing disappear issue?
<html>
<head>
<title>Canvas</title>
<style type="text/css">
#myCanvas{
border:1px solid red;
}
</style>
</head>
<body>
<canvas id = "myCanvas" width = "500px" height = "500px"></canvas>
<button id = "btn1" onclick = "resizeCanvas()">Resize</button>
</body>
<script type="text/javascript">
var canvasRef = document.getElementById('myCanvas');
var ctx = canvasRef.getContext("2d");
if (ctx) {
ctx.fillStyle = "rgb(200,0,0)";
ctx.fillRect (10, 10, 55, 50);
};
function resizeCanvas () {
canvasRef.width = 1000;
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment