svg复用方式<g>, <defs>, <symbol>, <use>

svg复用元素的方式主要有 <g>, <defs>, <symbol>, <use>

1. <g>

group, 分组,定义一组元素,初始不可见

<g id="group" fill="red">
   <rect x="10" y="10" width="100" height="100" />
   <rect x="120" y="10" width="100" height="100" />
</g>

2. <defs>

定义一些可供重用的元素,组,普通形状,渐变,mask,滤镜fliter,初始不可见

例如:

<defs>
    <g id="g1">
        <rect id="rect1" width="100" height="50" x="10" y="10" fill="#c00"/>
        <circle id="circle1" cx="30" cy="30" r="10" fill="#00c"/>
    </g>
    <linearGradient id="a1">
        <stop offset="5%" stop-color="#F00" />
        <stop offset="95%" stop-color="#ff0" />
    </linearGradient>
    <path id="a1" d="M0 50 C150 150 100 -50 300 50" stroke="#000" fill="none"/>
    <mask id="mask1"> 
        <rect  x="50" y="50" width="100" height="100" fill="#ccc"/>
        <rect  x="150" y="150" width="50" height="50" fill="#fff"/>
    </mask> 
    <filter width="200" height="200" x="0" y="0" id="blur" filterUnits="userSpaceOnUse">
        <feGaussianBlur stdDeviation="5" />
    </filter>
</defs>

3. <use>

使用定义的元素,包括<g>, <defs>

<use xlink:href="#g1"/>
<use xlink:href="#rect1" x="110"/>
<use xlink:href="#circle1" x="210"/>

4. <symbol>

定义可重复使用的符号,初始不显示,能够创建自己的视窗,所以能够应用viewBox和preserveAspectRatio属性

<symbol id="symbol" viewBox="0 0 250 250">
    <rect x="90" y="110" width="100" height="100" />
</symbol>
  
<use id="ant"
     transform="translate(0 110) rotate(10 0 0)"
     fill="red"
     xlink:href="#symbol" />

 

转载于:https://www.cnblogs.com/mengff/p/11360090.html

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 400"> <!-- 样式定义 --> <style> .process { fill: #4CAF50; stroke: #388E3C; stroke-width: 2; } .decision { fill: #FFC107; stroke: #FFA000; stroke-width: 2; } .io { fill: #2196F3; stroke: #1976D2; stroke-width: 2; } .startend { fill: #F44336; stroke: #D32F2F; stroke-width: 2; } .arrow { fill: none; stroke: #000; stroke-width: 2; marker-end: url(#arrowhead); } .text { font-family: Arial; font-size: 14px; fill: #000; text-anchor: middle; dominant-baseline: middle; } .title { font-family: Arial; font-size: 24px; font-weight: bold; fill: #000; text-anchor: middle; } </style> <!-- 箭头标记 --> <defs> <marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto"> <polygon points="0 0, 10 3.5, 0 7" fill="#000" /> </marker> </defs> <!-- 标题 --> <text x="600" y="30" class="title">循环双链表操作流程图</text> <!-- 节点 - 开始 --> <ellipse cx="100" cy="100" rx="50" ry="30" class="startend" /> <text x="100" y="100" class="text">开始</text> <!-- 节点 - 初始化链表 --> <rect x="220" cy="100" width="180" height="60" rx="10" class="process" /> <text x="310" y="100" class="text">初始化循环双链表</text> <!-- 节点 - 插入元素 --> <rect x="450" cy="100" width="180" height="60" rx="10" class="process" /> <text x="540" y="100" class="text">依次插入a,b,c,d,e</text> <!-- 节点 - 输出链表 --> <rect x="700" cy="100" width="150" height="60" rx="10" class="io" /> <text x="775" y="100" class="text">输出链表</text> <!-- 节点 - 链表长度 --> <rect x="890" cy="100" width="150" height="60" rx="10" class="process" /> <text x="965" y="100" class="text">计算链表长度</text> <!-- 节点 - 是否为空 --> <diamond x="1080" cy="100" width="60" height="60" class="decision" /> <text x="1110" y="100" class="text">是否为空</text> <!-- 节点 - 获取元素 --> <rect x="220" cy="200" width="150" height="60" rx="10" class="process" /> <text x="295" y="200" class="text">获取第3个元素</text> <!-- 节点 - 查找位置 --> <rect x="410" cy="200" width="150" height="60" rx="10" class="process" /> <text x="485" y="200" class="text">查找'a'的位置</text> <!-- 节点 - 插入元素 --> <rect x="600" cy="200" width="150" height="60" rx="10" class="process" /> <text x="675" y="200" class="text">在第4位插入'f'</text> <!-- 节点 - 输出链表 --> <rect x="790" cy="200" width="150" height="60" rx="10" class="io" /> <text x="865" y="200" class="text">输出链表</text> <!-- 节点 - 删除元素 --> <rect x="980" cy="200" width="150" height="60" rx="10" class="process" /> <text x="1055" y="200" class="text">删除第3个元素</text> <!-- 节点 - 输出链表 --> <rect x="220" cy="300" width="150" height="60" rx="10" class="io" /> <text x="295" y="300" class="text">输出链表</text> <!-- 节点 - 销毁链表 --> <rect x="410" cy="300" width="150" height="60" rx="10" class="process" /> <text x="485" y="300" class="text">销毁链表</text> <!-- 节点 - 创建对称链表 --> <rect x="600" cy="300" width="150" height="60" rx="10" class="process" /> <text x="675" y="300" class="text">创建对称链表</text> <!-- 节点 - 判断对称性 --> <diamond x="790" cy="300" width="60" height="60" class="decision" /> <text x="820" y="300" class="text">是否对称</text> <!-- 节点 - 输出结果 --> <rect x="920" cy="300" width="150" height="60" rx="10" class="io" />0" rx="10" class="io" /> <text x="995" y="300" class="text">输出判断结果</text> <!-- 节点 - 销毁对称链表 --> <rect x="1110" cy="300" width="150" height="60" rx="10" class="process" /> <text x="1185" y="300" class="text">销毁对称链表</text> <!-- 节点 - 结束 --> <ellipse cx="100" cy="300" rx="50" ry="30" class="startend" /> <text x="100" y="300" class="text">结束</text> <!-- 连接线 --> <path d="M150,100 L220,100" class="arrow" /> <path d="M400,100 L450,100" class="arrow" /> <path d="M630,100 L700,100" class="arrow" /> <path d="M840,100 L890,100" class="arrow" /> <path d="M1040,100 L1080,100" class="arrow" /> <path d="M1140,100 L1140,170 L220,170 L220,200" class="arrow" /> <path d="M370,200 L410,200" class="arrow" /> <path d="M560,200 L600,200" class="arrow" /> <path d="M740,200 L790,200" class="arrow" /> <path d="M940,200 L980,200" class="arrow" /> <path d="M1130,200 L1130,270 L980,270 L980,300" class="arrow" /> <path d="M850,300 L920,300" class="arrow" /> <path d="M1070,300 L1110,300" class="arrow" /> <path d="M1185,300 L1250,300" class="arrow" /> <path d="M600,230 L600,300" class="arrow" /> <path d="M750,300 L790,300" class="arrow" /> <path d="M485,300 L550,300" class="arrow" /> <path d="M150,300 L220,300" class="arrow" /> <path d="M295,300 L360,300" class="arrow" /> </svg>帮我修改一下
最新发布
05-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值