在我的代码的一部分中,我调用getContext('2d')一个canvas元素来生成CanvasRenderingContext2D对象.该对象继续在函数之间传递一个相当大的位,并且在代码的稍后部分,能够获得对canvas产生给定上下文的原始dom元素的引用是很方便的.我在规范中找不到任何东西,但似乎应该是可能的那种东西.想法?
我可以想到很多变通办法(传递canvas元素及其上下文等),但我的代码已经足够复杂了,我宁愿直接进行.
Sim*_*ris 10
所以你有你的背景:
var ctx = myCanvas.getContext('2d'); // the canvas' 2d context
Run Code Online (Sandbox Code Playgroud)
以后你可以随时做:
ctx.canvas // the context's canvas, which in this case is the same as myCanvas
Run Code Online (Sandbox Code Playgroud)
来自Canvas规范:
interface CanvasRenderingContext2D {
// back-reference to the canvas
readonly attribute HTMLCanvasElement canvas;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1338 次 |
| 最近记录: |