What is the getCSSCanvasContext() method of an HTML5 element?

二次信任 提交于 2021-02-04 14:40:12

问题


What is the getCSSCanvasContext() method? I saw it in Chrome’s debuging console, but I cannot find any decent documentation for it.

Does it mean we can draw using canvas commands on any element?


回答1:


The method is implemented in WebKit (meaning you can also use it in Safari) and returns an object that lets you draw into a CSS image. See this blog post for an example:

In the latest nightlies, you can try out a new feature: the ability to specify named image buffers in CSS and then to draw into them programmatically from JavaScript. Here’s how it works.

background: -webkit-canvas(mycanvas);

Instead of specifying an image URL, you specify a canvas and an identifier to use for that canvas. The following new API on documents can then be used to obtain a drawing context for that canvas.

CanvasRenderingContext getCSSCanvasContext(in DOMString contextType, in DOMString identifier, in long width, in long height);




回答2:


also don't use ctx.clearRect(0, 0, w, h); for IE9 - it doesn't work after this code if you try to draw something after clearRect() you will get empty canvas anyway



来源:https://stackoverflow.com/questions/3433010/what-is-the-getcsscanvascontext-method-of-an-html5-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!