SVG 放射性渐变radialGradient

2019-05-07 00:09|来源: 网路

SVG 放射性渐变 - <radialGradient>

<radialGradient>元素用于定义放射性渐变。

<radialGradient>标签必须嵌套在<defs>的内部。<defs>标签是definitions的缩写,它可对诸如渐变之类的特殊元素进行定义。


实例 1

定义一个放射性渐变从白色到蓝色椭圆:

下面是SVG代码:

实例

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <defs>
    <radialGradient id="grad1" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
      <stop offset="0%" style="stop-color:rgb(255,255,255);
      stop-opacity:0" />
      <stop offset="100%" style="stop-color:rgb(0,0,255);stop-opacity:1" />
    </radialGradient>
  </defs>
  <ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>

运行结果

1.png

代码解析:

  • <radialGradient>标签的 id 属性可为渐变定义一个唯一的名称

  • CX,CY和r属性定义的最外层圆和Fx和Fy定义的最内层圆

  • 渐变颜色范围可以由两个或两个以上的颜色组成。每种颜色用一个<stop>标签指定。offset属性用来定义渐变色开始和结束

  • 填充属性把ellipse元素链接到此渐变


实例 2

定义放射性渐变从白色到蓝色的另一个椭圆:

下面是SVG代码:

实例

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <defs>
    <radialGradient id="grad1" cx="20%" cy="30%" r="30%" fx="50%" fy="50%">
      <stop offset="0%" style="stop-color:rgb(255,255,255);
      stop-opacity:0" />
      <stop offset="100%" style="stop-color:rgb(0,0,255);stop-opacity:1" />
    </radialGradient>
  </defs>
  <ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>

运行结果

2.png


相关问答

更多
  • SVG无功补偿[2023-10-02]

    您好: SVG是通过电力电子器件IGBT和相应控制电路,对系统检测到的无功功率进行抵消,即:系统产生多大的无功功率,SVG就产生多大的无功功率,但这个无功是与系统无功反相的,将系统无功抵消。只要IGBT的开关频率足够快,不仅可以抵消系统的无功,还能抵消系统的谐波,这就是APF。电容补偿是通过减小cosφ来较小系统的无功损耗,而SVG则是通过抵消来消除无功损耗的。
  • 什么是SVG?[2022-08-22]

    SVG(可缩放矢量图形)编辑 可缩放矢量图形是基于可扩展标记语言(标准通用标记语言的子集),用于描述二维矢量图形的一种图形格式。它由万维网联盟制定,是一个开放标准。 中文名可缩放矢量图形 外文名Scalable Vector Graphics 外语缩写SVG 开发商万维网联盟 发行时间1999年 格 式矢量图 延伸至可扩展标记语言 类 型图形格式 目录
  • 其实我刚刚找到了答案。 为了只有一个渐变,可以将rotate变换应用到线上。 (在转换之前应用渐变)。
    你的far-gradient是一个svg,它有一个显示样式:none。 这会禁用该片段中的所有CSS,因此它不起作用。 尝试width =“0”height =“0”而不是display:none。 Your far-gradient is in an svg which has a style of display:none. That disables all CSS within that fragment so it doesn't work. Try width="0" height="0" in ...
  • 正如@Robert_Longson所述,您可以动态创建RadialGradient元素,然后将其应用于fill属性: 这是一种非常基本的方法,需要进行改进 ,以便将颜色和不同属性视为变量 $("#canvas-area").click(function(event) { $('body').append('
  • 我以为我可以设置cx或cy,但它们似乎没有做任何事情。 当cx和cy改变时似乎工作正常。 function createFog(imageUrl) { const mapImage = new Image(); mapImage.onload = function() { // Grab the dimensions of the map const width = this.width; const height = this.height; d ...
  • 您可以将这些添加到渐变svg样式规则中 visibility: hidden; position: absolute; 它会隐藏你的svg,并从你的页面流中取出svg元素,这样它就不会占用页面上的任何像素 You can add these to your gradient svg style rules visibility: hidden; position: absolute; It will hide your svg, and take that svg element out of your ...
  • 这是我的解决方案,但我相信有一个更容易。 我创建了两组带轮线的组。 其中一个具有我的渐变颜色的第二种颜色,另一个具有白色到黑色渐变的蒙版。 然后我用对它进行动画处理。 当我的车轮顺时针旋转时,我的渐变正在向后旋转。
  • 渐变在y方向上从0到152400,大于y = 152400的任何值将以最后一个停止颜色绘制。 椭圆y中心为304800,因此其最低点为304800 - 152400 = 152400,这是梯度终点。 The gradient runs from 0 to 152400 in the y direction, anything bigger than y=152400 will be drawn in the last stop colour. The ellipse y centre is 304800 s ...
  • dom / build构造没有命名空间的DOM元素。 您需要增强dom / build或为SVG编写一个。 我使用以下代码来创建SVG元素。 (defn element-ns "Create a namespaced dom element" [namespace tag & args] (let [[tag attrs children] (normalize-args tag args) parent (. js/document createElementNS namesp ...