Jump to content

canvas


etsted

Recommended Posts

what does it mean that i can back-reference the canvas element through the context object in this script?

 

alert(ctx.canvas.id+" | "+ctx.canvas.width+" | "+ctx.canvas.height);

 

in w3school they would only write "ctx.id".

Link to comment
Share on other sites

No, I don't believe they would write ctx.id because that wouldn't work.

You get a context object from a canvas element.

var ctx = canvas.getContext("2d");

If you somehow lost the reference to canvas but you still have the context you can get back to the canvas with

var canvas = ctx.canvas;
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...