从W3school上学习了一下SVG矢量图形,感觉和HTML相比还是有一些新的元素和属性的,一时间不能全部记住,特此留下笔记,供遗忘时作为参考

 <!DOCTYPE html>
<!-- 在<html>标签中声明SVG的XML方言xmlns:svg="http://www.w3.org/2000/svg" -->
<html xmlns:svg="http://www.w3.org/2000/svg"> <head>
<meta charset="utf-8" />
<title>SVG学习记录</title>
</head> <body>
<!-- SVG嵌入HTML的三种方式 -->
<!-- pluginspage:支持<embed>标签的插件的下载地址 -->
<embed src="svg/circle_example.svg" width="300" height="100" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" />
<!-- codebase:支持<object>标签的插件的下载地址 -->
<object data="svg/circle_example.svg" width="300" height="100" type="image/svg+xml" codebase="http://www.adobe.com/svg/viewer/install/"></object>
<iframe src="svg/circle_example.svg" width="300" height="100"></iframe>
<hr />
<svg width="300" height="100" version="1.1">
<circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" />
</svg>
<hr />
<p>矩形</p>
<svg width="100%" height="100%" version="1.1">
<rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:1; stroke:rgb(0,0,0)"/>
<!-- 左距离20,上距离20,宽度150,高度70,填充蓝色,边框粉色,边框5px,填充部分透明度0.1,边框透明度0.9 -->
<rect x="400" y="20" width="150" height="70" style="fill:blue;stroke:pink;stroke-width:5; fill-opacity:0.1;stroke-opacity:0.9"/>
</svg>
<svg width="100%" height="100%" version="1.1">
<!-- 定义整个svg的透明度 -->
<rect x="20" y="20" width="80" height="70" style="fill:blue;stroke:pink;stroke-width:5; opacity:0.6"/>
<!-- rx,ry:圆角弧度 -->
<rect x="120" y="20" rx="30" ry="20" width="250" height="50" style="fill:red;stroke:black; stroke-width:5;opacity:0.5"/>
</svg>
<hr />
<p>圆形</p>
<svg width="100%" height="100%" version="1.1">
<!-- cx,cy:横纵坐标 -->
<circle cx="100" cy="50" r="40" stroke="black" strok e-width="2" fill="red"/>
<!-- 椭圆 -->
<ellipse cx="200" cy="60" rx="20" ry="40" style="fill:rgb(200,100,50); stroke:rgb(0,0,100);stroke-width:2"/>
<!-- 累叠椭圆 -->
<ellipse cx="540" cy="100" rx="220" ry="30" style="fill:purple"/>
<ellipse cx="520" cy="70" rx="190" ry="20" style="fill:lime"/>
<ellipse cx="510" cy="45" rx="170" ry="15" style="fill:yellow"/>
<!-- 组合椭圆 -->
<ellipse cx="1040" cy="70" rx="220" ry="30" style="fill:yellow"/>
<ellipse cx="1020" cy="70" rx="190" ry="20" style="fill:white"/>
</svg>
<hr />
<p>线条</p>
<svg width="100%" height="100%" version="1.1">
<!-- x1,y1:开始点横纵坐标,x2,y2:结束点横纵坐标 -->
<line x1="10" y1="10" x2="300" y2="40" style="stroke:rgb(99,99,99);stroke-width:2"/>
</svg>
<hr />
<p>多边形</p>
<svg width="100%" height="100%" version="1.1">
<!-- points:多边形各个点所在位置 -->
<polygon points="0 10,100 130,150 70" style="fill:#cccccc; stroke:#000000;stroke-width:1"/>
<polygon points="240 5,60 20,160 70,240 70" style="fill:#cccccc; stroke:#000000;stroke-width:1"/>
</svg>
<hr />
<p>折线</p>
<svg width="100%" height="100%" version="1.1">
<!-- 折线各个转折点 -->
<polyline points="0,0 0,10 20,20 20,40 40,40 40,60" style="fill:white;stroke:red;stroke-width:2"/>
</svg>
<hr />
<p>路径</p>
<svg width="100%" height="100%" version="1.1">
<!-- 路径:(100,10) -> (10,100) -> (100,100) -> (100,10) -->
<path d="M100 10 L10 100 L100 100 Z" />
</svg>
<!-- 复杂图形建议使用SVG编辑器来进行绘制 -->
<svg width="100%" height="500px" version="1.1">
<path d="M153 334
C153 334 151 334 151 334
C151 339 153 344 156 344
C164 344 171 339 171 334
C171 322 164 314 156 314
C142 314 131 322 131 334
C131 350 142 364 156 364
C175 364 191 350 191 334
C191 311 175 294 156 294
C131 294 111 311 111 334
C111 361 131 384 156 384
C186 384 211 361 211 334
C211 300 186 274 156 274"
style="fill:white;stroke:red;stroke-width:2"/>
</svg>
<hr />
<p>可用滤镜</p>
<p>
<ul>
<li>feBlend</li>
<li>feColorMatrix</li>
<li>feComponentTransfer</li>
<li>feComposite</li>
<li>feConvolveMatrix</li>
<li>feDiffuseLighting</li>
<li>feDisplacementMap</li>
<li>feFlood</li>
<li>feGaussianBlur</li>
<li>feImage</li>
<li>feMerge</li>
<li>feMorphology</li>
<li>feOffset</li>
<li>feSpecularLighting</li>
<li>feTile</li>
<li>feTurbulence</li>
<li>feDistantLight</li>
<li>fePointLight</li>
<li>feSpotLight</li>
</ul>
</p>
<hr />
<p>高斯滤镜</p>
<svg width="100%" height="100%" version="1.1">
<defs>
<filter id="Gaussian_Blur">
<feGaussianBlur in="SourceGraphic" stdDeviation="3" />
</filter>
</defs>
<ellipse cx="200" cy="70" rx="70" ry="40" style="fill:#ff0000;stroke:#000000; stroke-width:2;filter:url(#Gaussian_Blur)"/>
</svg>
<svg width="100%" height="100%" version="1.1">
<defs>
<filter id="Gaussian_Blur">
<feGaussianBlur in="SourceGraphic" stdDeviation="20"/><!-- 20 -->
</filter>
</defs>
<ellipse cx="200" cy="70" rx="70" ry="40" style="fill:#ff0000;stroke:#000000; stroke-width:2;filter:url(#Gaussian_Blur)"/>
</svg>
<hr />
<p>线性渐变</p>
<svg width="100%" height="100%" version="1.1">
<defs>
<!-- <linearGradient> 标签的 id 属性可为渐变定义一个唯一的名称 -->
<!-- 水平渐变,x1,y1:渐变开始位置,x2,y2:渐变结束位置 -->
<linearGradient id="orange_red" x1="0%" y1="0%" x2="100%" y2="0%">
<!-- <stop>标签用于规定渐变中每个关键节点的颜色,offset用于标记其位置 -->
<stop offset="0%" style="stop-color:rgb(255,255,0); stop-opacity:1"/>
<stop offset="100%" style="stop-color:rgb(255,0,0); stop-opacity:1"/>
</linearGradient>
</defs>
<ellipse cx="200" cy="70" rx="85" ry="55" style="fill:url(#orange_red)"/>
<!-- 垂直渐变 -->
<defs>
<linearGradient id="orange-red" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" style="stop-color:rgb(255,255,0); stop-opacity:1"/>
<stop offset="100%" style="stop-color:rgb(255,0,0); stop-opacity:1"/>
</linearGradient>
</defs>
<ellipse cx="500" cy="70" rx="85" ry="55" style="fill:url(#orange-red)"/>
</svg>
<hr />
<p>放射渐变</p>
<svg width="100%" height="100%" version="1.1">
<defs>
<!-- 参考http://www.w3school.com.cn/svg/svg_grad_radial.asp -->
<!-- r:个人理解为内圈放射范围 -->
<!-- fx,fy:个人理解为内圈中心(即<stop>的offset=0%)所在相对位置 -->
<radialGradient id="grey_blue" cx="40%" cy="40%" r="50%" fx="20%" fy="60%">
<stop offset="0%" style="stop-color:rgb(200,200,200); stop-opacity:0.5"/>
<stop offset="100%" style="stop-color:rgb(0,0,255); stop-opacity:1"/>
</radialGradient>
</defs>
<ellipse cx="170" cy="60" rx="100" ry="50" style="fill:url(#grey_blue)"/>
<defs>
<!-- 个人理解 -->
<!-- cx,xy:如果点A(fx,fy)为中心,r为该中心点的放射范围,则B(cx,cy)可以表示为点A放射偏移方向的参照点,如果点A与点B位置重合,则表示放射没有偏移方向,即向四周等量放射-->
<radialGradient id="grey-blue" cx="50%" cy="50%" r="70%" fx="80%" fy="80%">
<stop offset="0%" style="stop-color:rgb(200,200,200); stop-opacity:0.5"/>
<stop offset="100%" style="stop-color:rgb(0,0,255); stop-opacity:1"/>
</radialGradient>
</defs>
<rect x="500" y="20" width="250" height="100" style="fill:url(#grey-blue);"/>
</svg>
<hr />
<p>动画</p>
<!-- 参考:http://www.w3school.com.cn/svg/svg_examples.asp -->
<!-- 淡出效果 -->
<svg width="100%" height="100%" version="1.1">
<rect x="20" y="20" width="250" height="250" style="fill:blue">
<animate attributeType="CSS" attributeName="opacity" from="1" to="0" dur="5s" repeatCount="indefinite" />
</rect>
<!--</svg>-->
<!-- 动态改变多个属性 -->
<!--<svg width="100%" height="100%" version="1.1">-->
<rect id="rec" x="900" y="100" width="300" height="10" style="fill:lime">
<animate attributeName="x" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="900" to="600"/>
<animate attributeName="y" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="100" to="0"/>
<animate attributeName="width" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="300" to="100"/>
<animate attributeName="height" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="10" to="100"/>
<animateColor attributeName="fill" attributeType="CSS" from="lime" to="gray" begin="1s" dur="5s" fill="freeze"/>
</rect>
</svg>
<svg width="100%" height="100%" version="1.1">
<g transform="translate(50,50)">
<text id="TextElement" x="0" y="0" style="font-family:Verdana;font-size:24">沿路径平移
<animateMotion path="M 0 0 L 50 50" dur="3s" fill="freeze"/>
</text>
</g>
</svg>
<svg width="100%" height="100%" version="1.1">
<g transform="translate(100,100)">
<text id="TextElement" x="0" y="0" style="font-family:Verdana;font-size:22; visibility:hidden"> 平移+旋转+缩放
<set attributeName="visibility" attributeType="CSS" to="visible" begin="1s" dur="5s" fill="freeze"/>
<animateMotion path="M 0 0 L 100 30" begin="1s" dur="5s" fill="freeze"/>
<animateTransform attributeName="transform" attributeType="XML" type="rotate" from="-30" to="0" begin="1s" dur="5s" fill="freeze"/>
<animateTransform attributeName="transform" attributeType="XML" type="scale" from="1" to="3" additive="sum" begin="1s" dur="5s" fill="freeze"/>
</text>
</g>
</svg>
<p>SVG元素属性参考手册: <a href="http://www.w3school.com.cn/svg/svg_reference.asp">参考W3School描述</a></p>
</body> </html>

SVG矢量图学习实例的更多相关文章

  1. Android中使用SVG矢量图(一)

    SVG矢量图介绍 首先要解释下什么是矢量图像,什么是位图图像? 1.矢量图像:SVG (Scalable Vector Graphics, 可伸缩矢量图形) 是W3C 推出的一种开放标准的文本式矢量图 ...

  2. Android 使用 SVG 矢量图

    android svg矢量图 可能包含的操作有: SVG图还包括改变颜色,透明度,大小,矩阵操作(平移.旋转.缩放),selector, (图标,背景,按钮),动画,等 setTint(int Col ...

  3. Perl+OpenGL 重绘inkscape生成的svg矢量图

    Perl+OpenGL 重绘inkscape生成的svg矢量图 还不够完善,先挖个坑,后面慢慢填 Code: [全选] [展开/收缩] [Download] (Untitled.pl) =info A ...

  4. svg矢量图绘制以及转换为Android可用的VectorDrawable资源

    项目需要 要在快速设置面板里显示一个VoWiFi图标(为了能够区分出来图形,我把透明的背景填充为黑色了) 由于普通图片放大后容易失真,这里我们最好用矢量图(SVG(Scalable Vector Gr ...

  5. svg矢量图

    svg简介 Scalable Vector Graphics 可缩放矢量图形 SVG 图像在放大或改变尺寸的情况下其图形质量不会有所损失 svg知识点 svg如何绘图 svg和cnavas区别 svg ...

  6. svg矢量图在flex布局中样式扭曲的问题

    问题机型 小米5 华为nova 其他未知的可能机型 问题描述 利用flex 布局的一行中, 左一样式: -webkit-box-flex: 0; flex: 0 1 auto; 左二样式: -webk ...

  7. SVG矢量图【转】

    var iconArray=[ //'circle', //实心圆 //'rect', //矩形 //'roundRect', //圆角矩形 //'triangle', //三角形 //'diamon ...

  8. SVGO: Node.js 开发的 SVG 矢量图优化工具(svg压缩工具)

    SVG图片压缩 这是个通过借助npm包的一种方式去压缩svg的图片,由于阿里的图库自己创建的图标有大小的限制,当我们想要自己用自己的图标的时候就可以使用这种方式去完成对svg的图片压缩. 1.下载no ...

  9. SVG矢量图--爱心

    aixin.xml: <!-- height:width=viewportHeight:viewportWidth --> <vector xmlns:android="h ...

随机推荐

  1. AJAX发送PUT请求引发的血案

    如果直接发送ajax=put形式的请求      是拿不到请求体中的数据的.           Tomcat:              1.将请求体中的数据,封装一个map             ...

  2. Dynamics 365中显示格式为URL的字段极少部分URL值录入了不显示怎么回事?

    微软动态CRM专家罗勇 ,回复318或者20190315可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 对于如下类型的字段, ...

  3. 基于Html5 Plus + Vue + Mui 移动App 开发(二)

    基于Html5 Plus + Vue + Mui 移动App 开发(二) 界面效果: 本页面采用Html5 Plus + Vue + Mui 开发移动界面,本页面实现: 1.下拉刷新.上拉获取更多功能 ...

  4. android - TextView单行显示...或者文字左右滚动(走马灯效果)

    条件 TextView单行显示,文字左右滚动(走马灯效果)实现条件: 实现单行设置固定宽度或者设置权重都行 代码 TextView滚动必须写下面几个属性 android:singleLine=&quo ...

  5. IntentService原理分析

    IntentService是一个异步处理请求的服务,通过Context#startService(Intent)可以将请求发送给IntentService,IntentService在工作线程中依次串 ...

  6. 【English】十四、英语

    一.英语 是 词法(词) + 语法 一个个拥有词法的词,就是材料.通过语法的规则将这些词合理组合排列起来.然后,就可以干很多事了.

  7. MyDAL - .Where() & .And() & .Or() 使用

    索引: 目录索引 一.API 列表 1.Where .Where(Func<M, bool> func) 如: .Where( it => (it.Prop1>=条件1 &am ...

  8. 将CSV文件写入MySQL

    先打开CSV文件查看第一行有哪些字段,然后新建数据库,新建表.(若字段内容很多建议类型text,如果设成char后续会报错) 命令如下: load data infile '路径XXXX.csv' i ...

  9. Linux- 常用命令, Vim编辑器操作

    1.Linux命令: ls >查看列表(蓝色为文件夹,白色为文件) ls -a >显示包括隐藏文件的所有文件 ls -l >以列表的形式显示 ls -lh >类似于ls -l ...

  10. LeetCode算法题-Longest Word in Dictionary(Java实现)

    这是悦乐书的第303次更新,第322篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第171题(顺位题号是720).给出表示英语词典的字符串单词数组,找到单词中长度最长的单 ...