Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can canvas tag be used to draw on top of other items on a page?

Can an HTML canvas tag be positioned over other html content on a page? For example, will something the following CSS declaration make a canvas tag do what I expect it to?

canvas.mycanvas {
  position: absolute;
  background: transparent;
  z-index: 10;
  top: 10px; left: 10px;
}
like image 524
Devon Avatar asked Feb 28 '23 23:02

Devon


2 Answers

That should work perfectly. There's no need to set the background to 'transparent' though.

Overlaying a canvas is how this bookmarklet works.

like image 119
James Avatar answered May 02 '23 00:05

James


Yes, this works fine in canvas-supporting browsers, and furthermore works equally as well in IE6 and IE7 using the exCanvas project which translate canvas commands into Microsoft's XML-based vector language, VML.

One thing I noticed when attempting to overlay canvas elements across-browsers is that you have to be especially careful with the order in which you append and subsequently access any canvas child DOM nodes. IE needs the item to be appended before you can work with it.

like image 33
Gavin Avatar answered May 01 '23 23:05

Gavin