|
canvas
Aug 18, 2009 9:32:16 GMT -5
Post by kokenge on Aug 18, 2009 9:32:16 GMT -5
I have a very simple "canvas" example that I cannot get to work. I've tried this in HTML and it works. I know the draw() command is working because I put a alert in the draw function. Like I say this works in html so the <canvas command works. I enclosed the <canvas> command in <script> and </script> and that didn't seem to work.. What am I doing wrong?? I'm using the chrome browser. IE does not have HTML-5 yet. html "<script language='javascript'> <!-- function draw() { var canvas = document.getElementById('canvas'); if (canvas.getContext) { var ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgb(200,0,0)'; ctx.fillRect (10, 10, 55, 50); ctx.fillStyle = 'rgba(0, 0, 200, 0.5)'; ctx.fillRect (30, 30, 55, 50); } } //--></script>"
html "<script>draw();</script>" html "<canvas id='canvas' width='150' height='150'></canvas>" wait
Thanks for the help.. Have a great day..
|
|
Core
Junior Member
Posts: 54
|
canvas
Aug 18, 2009 14:37:23 GMT -5
Post by Core on Aug 18, 2009 14:37:23 GMT -5
Move the <canvas> tag up one. You are calling JS Before the element is created. html "<script type ='text/javascript'>
function draw() { var canvas = document.getElementById('canvas'); if (canvas.getContext) { var ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgb(200,0,0)'; ctx.fillRect (10, 10, 55, 50); ctx.fillStyle = 'rgba(0, 0, 200, 0.5)'; ctx.fillRect (30, 30, 55, 50); } } </script>" html "<canvas id='canvas' width='150' height='150'></canvas>" html "<script>draw();</script>"
wait
This works for me Respectfully, Core
|
|
|
canvas
Aug 18, 2009 14:59:48 GMT -5
Post by kokenge on Aug 18, 2009 14:59:48 GMT -5
DUH! Too obvious .. Thank you soooo much core..
Dan
|
|