svg学习笔记(一)
SVG——可扩展适量图形,基于XML
PC端:IE9+ wap端:表现良好,适合使用
基础图形:
line(线段) <line x1="25" y1="150" x2="375" y2="50" stroke="#f00"></line>
polyline(折线) <polyline points="250 75,350 100,100 0" stroke="#1A9EF2" fill="none"></polyline>
circle(圆) <circle cx="135" cy="35" r="20" style="stroke: none;fill: #ddd;"></circle>
rect(矩形) <rect x="10" y="10" rx="10" ry="10" width="50" height="60" style="stroke: #ccc;fill:#add;"></rect>
polygon(多边形) <polygon points="400 400,450 480,600,100,550 80"></polygon>
ellipse(椭圆) <ellipse cx="200" cy="500" rx="72" ry="45"></ellipse>
组标签:
<g fill="dodgerblue">
<rect x="510" y="10" width="40" height="40" ry="10"/>
<rect x="610" y="80" width="40" height="40" ry="10" />
<rect x="710" y="150" width="40" height="40" ry="10" />
</g>
a链:
<a xlink:href="http://sina.com.cn" target="_blank">
<text x="10" y="130" style="fill: red;">Hello World!!</text>
</a>
路径标签:(M——移动 L——线段 H——水平线段 V——垂直线段 A——圆弧 C——三次贝塞尔曲线 S——特殊版本的三次贝塞尔曲线 Q——二次贝塞尔曲线 T——特殊版本的二次贝塞尔曲线 Z——闭合)
<path d="M 60 0 L 120 0 L 180 60 L180 120 L120 180 L 60 180 L 0 120 L 0 60" transform="translate(500,500)"></path>
svg嵌入页面的方式:img、background、iframe、embed、object、直接使用svg标签嵌入
svg生成工具软件:Adobe Illustrator、SVGDeveloper
path的两个css属性:
stroke-dasharray /*两个参数:线段长度 线段缝隙*/
stroke-dashoffset /*从哪个位置开始渲染线段*/
获取path长度的js api: getTotalLength方法
通过改变path的两个属性,实现一个动画的效果:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
<title>路径描边动画2</title>
<style>
path:first-child{
stroke-dasharray: 1089.82;/*两个参数:线段长度 线段缝隙*/
stroke-dashoffset: 1089.82; /*从哪个位置开始渲染线段*/
}
path:last-child{
stroke-dasharray: 1288.02;
stroke-dashoffset: 1288.02;
}
path{
animation: dash 5s linear infinite;
}
@keyframes dash {
to{
stroke-dashoffset: 0;
}
}
</style>
</head>
<body>
<svg width="640" height="480" version="1.1" xmlns="http://www.w3.org/2000/svg">
<path d="M 58 88 C 60.99994 87.33333 71.5 84.66666 76 84 C 80.49994 83.33333 82.16663 84.16666 85 84 C 87.83331 83.83333 89 80.16666 93 83 C 96.99994 85.83333 105.6666 92.83333 109 101 C 112.3333 109.1667 116.9999 124.8333 113 132 C 109 139.1667 93.66663 138.6667 85 144 C 76.33331 149.3333 61.99994 160.5 61 164 C 60 167.5 72.16663 165.6667 79 165 C 85.83331 164.3333 94.66663 156.3333 102 160 C 109.3333 163.6667 121.1666 175.6667 123 187 C 124.8333 198.3333 118.6666 216.1667 113 228 C 107.3333 239.8333 92.33331 253.8333 89 258 C 85.66663 262.1667 94.99994 257.3333 93 253 C 91 248.6667 81.83331 239.3333 77 232 C 72.16663 224.6667 55.66663 222.5 64 209 C 72.33331 195.5 103.8333 164 127 151 C 150.1666 138 193.1666 138.6667 203 131 C 212.8333 123.3333 191.9999 112.6667 186 105 C 180 97.33333 171.3333 75.83333 167 85 C 162.6666 94.16666 163.4999 133.8333 160 160 C 156.5 186.1667 144.8333 238.3333 146 242 C 147.1666 245.6667 159.5 199.3333 167 182 C 174.4999 164.6667 189.1666 146.8333 191 138 C 192.8333 129.1667 182.6666 130.5 178 129 C 173.3333 127.5 158.1666 118.8333 163 129 C 167.8333 139.1667 187.6666 171.6667 207 190 C 226.3333 208.3333 267 230.8333 279 239 " fill="#FFFFFF" stroke="#000000" />
<path d="M 430 64 C 432.4999 67.33333 440 76.83333 445 84 C 449.9999 91.16666 464.9999 101.6667 460 107 C 455 112.3333 430.4999 113.6667 415 116 C 399.5 118.3333 373.3333 120.1667 367 121 C 360.6666 121.8333 361.6666 123 377 121 C 392.3333 119 432.3333 113.8333 459 109 C 485.6666 104.1667 529.6666 92.49998 537 92 C 544.3333 91.5 514.4999 99.16666 503 106 C 491.5 112.8333 473.8333 124.3333 468 133 C 462.1666 141.6667 466.8333 156.3333 468 158 C 469.1666 159.6667 474.5 146.5 475 143 C 475.4999 139.5 477.8333 135.8333 471 137 C 464.1666 138.1667 446.8333 142.5 434 150 C 421.1666 157.5 400.4999 173.1667 394 182 C 387.5 190.8333 394.6666 196.6667 395 203 C 395.3333 209.3333 396.6666 212 396 220 C 395.3333 228 392.6666 246.5 391 251 C 389.3333 255.5 379.5 257.5 386 247 C 392.4999 236.5 402.3333 202.1667 430 188 C 457.6666 173.8333 541 164.1667 552 162 C 562.9999 159.8333 511.1666 171.3333 496 175 C 480.8333 178.6667 466.8333 177.3333 461 184 C 455.1666 190.6667 462.3333 205.3333 461 215 C 459.6666 224.6667 454.6666 238.8333 453 242 C 451.3333 245.1667 448.6666 240.5 451 234 C 453.3333 227.5 458.5 212.3333 467 203 C 475.4999 193.6667 493.6666 177 502 178 C 510.3333 179 512.6666 197.8333 517 209 C 521.3333 220.1667 520 242.5 528 245 C 535.9999 247.5 552.1666 232 565 224 C 577.8333 216 600.1666 206 605 197 C 609.8333 188 595.8333 174.5 594 170 " fill="#FFFFFF" stroke="#000000" />
</svg> <script>
var paths = document.querySelectorAll('path'),path0=paths[0],path1=paths[1];
var path0Len=path0.getTotalLength(),path1Len=path1.getTotalLength();
console.log(path0Len+';'+path1Len)
</script>
</body>
</html>
svg学习笔记(一)的更多相关文章
- 8. svg学习笔记-文本
毫无疑问,文本也是svg中组成的重要部分,在svg中,用<text>元素来创建文本,文本的使用格式如下: <text x="20" y="30" ...
- 4. svg学习笔记-文档结构元素和样式的使用
svg除了绘图元素之外还有一部分是专门用于文档结构的,这类元素有<g>,<use>,<defs>,<symbol>等 <g>元素 如果我们仅 ...
- 2. svg学习笔记-svg中的坐标系统和viewbox
我是通过<SVG精髓>这本书学习的svg,说实话,这本书写的不好,或者说翻译的不好,我没有看过这本书的原版,不知道原文写的怎么样,但是翻译出来的有些句子真的很拗口.以前老师给我们API文档 ...
- svg的基本图形与属性【小尾巴的svg学习笔记1】
因为项目有可能用到, 所以学习了一下,做此笔记,图截自慕课网,侵删. 一.基本图形 1.矩形 x,y定义矩形的左上角坐标: width,height定义矩形的长度和宽度: rx,ry定义矩形的圆角半径 ...
- svg学习笔记(二)
SMIL animation演示代码集锦 <svg width="1400" height="1600" xmlns="http://www.w ...
- svg学习笔记
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 9. svg学习笔记-裁剪和蒙版
裁剪 在svg中进行剪切,对整个svg元素而言,可以使用<svg>元素的viewbox属性,对于单个元素则可以使用<clipPath>元素.在单个图形元素上使用裁剪,可以在&l ...
- 7. svg学习笔记-图案和渐变
之前,我们仅仅使用纯色来为图形填充颜色和绘制轮廓,除此之外,我们还可以使用图案和渐变来填充图形或者是绘制轮廓. 图案 图案的效果类似于,在网页中给一个元素指定背景图像,当背景图像的尺寸小于元素的尺寸的 ...
- 6. svg学习笔记-路径
路径相比于多边形<polygon>元素具有更强绘图能力,<polygon>元素可以绘制任意的多边形,而路径可以绘制任意的轮廓线,是线段,曲线,圆弧的组合形式.svg中可以使用& ...
随机推荐
- nginx+tomcat动静分离的核心配置
#所有jsp的页面均交由tomcat或resin处理 location ~ .(jsp|jspx|do)?$ { proxy_set_header Host $host; proxy_set_head ...
- nginx学习七 高级数据结构之动态数组ngx_array_t
1 ngx_array_t结构 ngx_array_t是nginx内部使用的数组结构.nginx的数组结构在存储上与大家认知的C语言内置的数组有相似性.比方实际上存储数据的区域也是一大块连续的内存. ...
- 文件I/O(不带缓冲)概述
一.引言 UNIX系统中大多数文件I/O只需用到5个函数:open.read.write.lseek以及close.这些函数经常被称为不带缓冲的I/O(unbuffered I/O).术语不带缓冲指的 ...
- 文件I/O之/dev/fd
较新的系统都提供名为/dev/fd的目录,其目录项是名为0.1.2等的文件.打开文件/dev/fd/n等效于复制描述符n(假定描述符n是打开的). 在下列函数调用中: fd = open( " ...
- C#_MVC_Repository_CURD_Controller
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- centos6.5 安装jdk7和tomcat7
JDK安装: 安装说明 系统环境:centos-6.5安装方式:rpm安装软件:jdk-7-linux-x64.rpm下载地址:http://www.oracle.com/technetwork/ja ...
- PHP读书笔记(2)-变量与数据结构
php中的数据类型: 一.8种主要数据类型 标量类型 1.整型(int|integer):八进制.十进制.十六进制.超过整型存储范围,会产生溢出. 整型数的字长和平台有关,尽管通常最大值是大约二十亿( ...
- C# for AUTOCAD ActiveX获取图形对象坐标程序
C# for AUTOCAD ActiveX获取图形对象坐标程序 using System;using System.Collections.Generic;using System.Componen ...
- 关于Java中return和finally谁先执行.
例子一: public class A { public static void main(String[] args) { System.out.print(tt()); } public stat ...
- gvim设置字体和隐藏菜单栏工具栏
liunx下面设置字体 set guifont=Monaco\ 注意空格的位置,其他写法不认哦! Windows下面设置 set guifont=Monaco:h 隐藏菜单栏 set guioptio ...