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>, <symbol>

<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" />

最新文章

  1. controller错误统一处理--------@ExceptionHandler
  2. (地址)eclipse插件开发攻略的访问地址
  3. PHP 设计模式 笔记与总结(7)适配器模式
  4. [实变函数]2.1 度量空间 (metric space), $n$ 维 Euclidean 空间
  5. js中ajax如何解决跨域请求
  6. mongodb使用中遇到的问题汇总
  7. GridBagLayout:网格包布局管理器
  8. eclipse的使用、优化配置
  9. 不建议用wxWidgets,底层有过多的bug
  10. Js遍历Josn对象(内容对比页实现思路)
  11. linux下通过yum安装svn及配置
  12. block 解析 - 形参变量
  13. Spark之UDAF
  14. Django ORM模型
  15. (7)Java数据结构--集合map,set,list详解
  16. 9.28 h5日记
  17. 准备尝试openFrameworks
  18. P3810 【模板】三维偏序(陌上花开)
  19. OAF 返回供应商门户主页
  20. 使用不安全代码将 Bitmap 位图转为 WPF 的 ImageSource 以获得高性能和持续小的内存占用

热门文章

  1. MySQL/MariaDB数据库的性能测试
  2. 51nod 2489 小b和灯泡
  3. Spring容器、BeanFactory和ApplicationContext,及3种装配Bean的方式
  4. 【python】Requests的三种参数请求方式
  5. vue $emit、$on、$refs简介
  6. tensorflow API _ 6 (tf.gfile)
  7. Access数据库连接封装类
  8. Boosting and AdaBoost
  9. CentOS yum repo
  10. zzulioj - 2628: 小新的字母广场