javascript - 如何在javascript中应用图像而不是线性渐变
问题描述
我在一个 svg 中应用了线性渐变颜色代码。现在我想将颜色代码替换为任何一个图像作为 svg 中的背景。
我的线性颜色渐变代码如下:
var ctx = ['rgba(243, 234, 255, 0.5)', 'rgba(134,104,155, 0.5)'];
var ctxValue = this.svg
.append('defs')
.append('linearGradient')
.attr('x1', '0%')
.attr('x2', '0%')
.attr('y1', '0%')
.attr('y2', '100%');
ctxValue
.selectAll('stop')
.data(ctx)
.enter()
.append('stop')
.style('stop-color', function(d) {
return d;
})
.attr('offset', function(d, i) {
return 100 * (i / (ctx.length - 1)) + '%';
});
var linearColor = '#ctxValue-' + valId;
this.ctxPattern.style('fill', 'url(' + linearColor + ')');
现在颜色渐变作为 svg 的背景。
如何在 svg 中应用图像而不是颜色渐变。任何人请帮助。
解决方案
推荐阅读
- android - 如何允许 new View.OnClickListener() 在 android studio 中运行?
- angular - 如何在 Angular 12 中导入默认导出的 graphql 查询?
- asp.net - 如何在“主布局”中使用“用户面板布局”?
- javascript - 反应加密密码
- ios - 为什么子类化主 ViewController 的视图会导致委托永远不会触发?
- android - 如何在相机应用程序上显示文本而不记录它#Android #Camera API
- meson-build - 介子:连接两个没有'/'的字符串
- docker - 带有 docker 的烧瓶 reqparser.parse_args 传递省略号对象 - 错误
- javascript - Google oAuth Google 健身
- html - 如何从 HTM 获取输入整数?- Arduino / NodeMCU ESP32