HTML 5 画布填充颜色
HTML 5 canvas fill color
我在使用以下脚本时遇到问题
var ctx = demo.getContext('2d'),
w = demo.width,
h = demo.height,
img = new Image,
url = 'http://i.imgur.com/1xweuKj.png',
grd = ctx.createLinearGradient(0, 0, 0, h);
grd.addColorStop(0, 'rgb(0, 130, 230)');
grd.addColorStop(1, 'rgb(0, 20, 100)');
img.onload = loop;
img.crossOrigin = 'anonymous';
img.src = url;
function loop(x) {
/// since we will change composite mode and clip:
ctx.save();
/// clear background with black
ctx.fillStyle = '#000';
ctx.fillRect(0, 0, w, h);
/// remove waveform, change composite mode
ctx.globalCompositeOperation = 'destination-atop';
ctx.drawImage(img, 0, 0, w, h);
/// fill new alpha, same mode, different region.
/// as this will remove anything else we need to clip it
ctx.fillStyle = grd;
ctx.rect(0, 0, x, h);
ctx.clip(); /// et clipping
ctx.fill(); /// use the same rect to fill
/// remove clip and use default composite mode
ctx.restore();
/// loop until end
}
当我这样做时loop(40)
这有效,然后如果我这样做loop(50)
那么它也有效,但是当我想给出比当前值更小的值(如loop(20)
)时,它不起作用。
任何人都可以让我知道这里有什么问题吗?
它适用于所有递增的值,但不适用于递减值。
检查 jsfiddle
我想
出了解决方法,现在工作正常。
我通过ctx.beginPath();
实现了它
相关文章:
- 椭圆字幕选择,然后在Photoshop中使用Javascript填充颜色
- 如何访问svg内部id并让CSS更改该id的填充颜色
- 如何使用fabricjs在图像中插入填充颜色
- 边距和输入元素边框之间的填充颜色
- OL3:如何获取矢量图层的现有样式属性(例如填充颜色、描边颜色等)
- 无法重置 SVG 路径的填充颜色
- 当 y 轴反转时是否可以保持填充颜色
- 我可以用LeafLet更改GeoJSON LineString的填充颜色吗?
- 如何在单击 SVG 用作背景图像时更改其填充颜色
- HTML 5 画布填充颜色
- 美国地图拉菲尔插件自动更新和动态填充颜色
- 更改高图表散点图中的制造商填充颜色
- 更改 svg 填充颜色,然后绘制到画布
- 我可以根据图表中的给定阈值设置不同的填充颜色吗.js
- 无法在谷歌地图符号 (svg) 标记中填充颜色
- Highcharts 图形默认系列填充颜色覆盖状态填充颜色(包括 jsfiddle)
- 如何获取HTML5画布元素的填充颜色
- 更改d3.js节点的填充颜色
- Highcharts-悬停时x坐标之间的不同填充颜色
- OpenLayers 3根据要素参数值更改点填充颜色