是否可以将从画布上下文创建的渐变应用于其他画布上下文
Can I apply gradients created from a canvas context to other canvas contexts?
是否可以将从画布上下文创建的渐变应用于其他画布上下文,如以下代码所示?
var canvasContextA = document.getElementById("canvasA").getContext("2d");
var canvasContextB = document.getElementById("canvasB").getContext("2d");
var gradientFromCanvasContextA = canvasContextA.createLinearGradient(0, 0, 100, 0);
gradientFromCanvasContextA.addColorStop(0, "black");
gradientFromCanvasContextA.addColorStop(1, "white");
canvasContextB.fillStyle = gradientFromCanvasContextA;
你能根据标准给我一个答案吗?这是一种未定义的行为吗?
有趣的问题。我在 Canvas 2D 规格中找到了这个注释:
In the case of addColorStop() on CanvasGradient, the "computed value of the 'color' property" for the purposes of determining the computed value of the currentColor keyword is always fully opaque black (there is no associated element). [CSSCOLOR]
This is because CanvasGradient objects are canvas-neutral — a CanvasGradient object created by one canvas can be used by another, and there is therefore no way to know which is the "element in question" at the time that the color is specified.
似乎暗示您可以按照要求进行操作,但仅适用于渐变和可能的字体属性。
相关文章:
- 将函数的上下文应用于javascript变量
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 使用JQuery的动态上下文菜单
- 如何访问UIWebView'的子窗口上下文
- Highcharts colorsByPoint与系列中的线性渐变一起使用时不起作用
- JQuery在单击正文时隐藏上下文菜单
- JQuery上下文菜单显示/隐藏问题
- 如何从HTTP上下文对象中获取Post数据
- HTML字符串作为上下文
- 在SVG地图上添加水的渐变,就像在谷歌地图(PHP/JS)中一样
- 为什么我的上下文选择器和.buttonset()在ie中花费了这么长时间
- 丢失对象“;这个“;方法中的上下文
- 防止在移动Safari(iPad/iPhone)中长按/长按默认上下文菜单
- d3防止在上下文菜单上触发mouseout
- 画布使用带有角度的线性渐变背景集
- 是否可以在不更改上下文的情况下调用函数.apply
- 在文本区域的焦点上分割渐变
- 调用$.each()函数时上下文发生变化
- Chart.js-添加渐变而不是纯色-实现解决方案
- 是否可以将从画布上下文创建的渐变应用于其他画布上下文