UNPKG

use-on-demand

Version:
259 lines (226 loc) 9.46 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Svg Demo</title> </head> <body> <!--小猫--> <svg width='140' heiight='170' xmlns='http://wwww.w3.org/2000/svg'> <title>Cat</title> <desc>Stick Figure of Cat</desc> <!-- 在这里绘制图像 --> <!--圆圈--> <circle cx='70' cy='95' r='50' style='stroke:black; fill:none'></circle> <!--左眼--> <circle cx='55' cy='80' r='5' stroke='black' fill='#3339933'></circle> <!--右眼--> <circle cx='85' cy='80' r='5' stroke='black' fill='#3339933'></circle> <!--分组--> <g id='whiskers'> <line x1='75' y1='95' x2='135' y2='85' style='stroke:black'></line> <line x1='75' y1='95' x2='135' y2='105' style='stroke:black'></line> </g> <!--WARN 将前一个分组,直接反向--> <use xlink:href="#whiskers" transform='scale(-1 1) translate(-140 0)'></use> <!-- 耳朵 --> <polyline points='108 62,90 10, 70 45, 50, 10, 32, 62' style='stroke:black; fill:none' /> <!-- 嘴 --> <polyline points='35 110,45 120, 95 120, 105, 110' style='stroke:black; fill:none' /> <!-- 鼻子 --> <path d='M 75 90 L 65 90 A 5 10 0 0 0 75 90' style='stroke:black; fill:#ffcccc' /> <!--FIXME 文字。但这里怎么没有显示???--> <text x="60" y="165" style='font-family:sans-serif;font-size: 14pt;stroke:none; fill: black;'>Cat</text> </svg> <!--两道斜线--> <svg width='280' heiight='340' xmlns='http://wwww.w3.org/2000/svg'> <line x1='0' y1='0' x2='100' y2='100' style='stroke:black' /> <line x1='100' y1='0' x2='200' y2='100' style='stroke-width:10;stroke:black' /> </svg> <!--彩色 颜色笔触--> <svg width='140' height='170' xmlns='http://wwww.w3.org/2000/svg'> <!-- 红色 --> <line x1='10' y1='10' x2='50' y2='10' style='stroke-width:5;stroke:red' /> <!-- 谈绿色 --> <line x1='10' y1='20' x2='50' y2='20' style='stroke-width:5;stroke:#9f9f;stroke-opacity: 0.2' /> <!-- 橘色 --> <line x1='10' y1='40' x2='50' y2='40' style='stroke-width:5;stroke:rgb(255,128,64);stroke-opacity: 0.5' /> <!-- 深紫色 --> <line x1='10' y1='50' x2='50' y2='50' style='stroke-width:5;stroke:rgb(60%,20%,60%);stroke-opacity: 0.8' /> </svg> <!--虚线--> <svg width='200' height='200' xmlns='http://wwww.w3.org/2000/svg'> <!-- 9个像素的虚线,5个像素的空隙 --> <line x1='10' y1='10' x2='100' y2='10' style='stroke-dasharray:9, 5; stroke: black; stroke-width:2' /> <!-- 5个像素的虚线,3个像素的空隙 ,9个像素的虚线,2个像素的空隙 --> <line x1='10' y1='30' x2='100' y2='30' style='stroke-dasharray:9, 5, 9, 2; stroke: black; stroke-width:2' /> <!-- 复制奇数个数 --> <line x1='10' y1='50' x2='100' y2='50' style='stroke-dasharray:9, 3, 5; stroke: black; stroke-width:2' /> </svg> <!--矩形--> <svg width='300' height='500' xmlns='http://wwww.w3.org/2000/svg'> <!-- 内部填充为黑色,不绘制边框 --> <rect x='10' y='10' width='30' height='50' /> <!-- 内部填充为蓝色,绘制较粗,半透明红色边框--> <!--TIP 边框笔触,填充颜色--> <rect x='50' y='10' width='30' height='50' style='fill: #0000ff;stroke: red;stroke-width: 7; stroke-opacity: .5' /> <!-- rx 和 ry 相等,逐渐增大--> <rect x='10' y='70' rx='2' ry='2' width='20' height='40' style='stroke:black; fill:none' /> <!-- rx 和 ry 相等,逐渐增大--> <rect x='50' y='70' rx='5' width='20' height='40' style='stroke:black; fill:none' /> <!-- rx 和 ry 不相等 --> <rect x='10' y='130' rx='10' ry='5' width='20' height='40' style='stroke:black; fill:none' /> <rect x='50' y='130' rx='10' ry='5' width='10' height='40' style='stroke:black; fill:none' /> </svg> <!--圆形、椭圆--> <svg width='300' height='500' xmlns='http://wwww.w3.org/2000/svg'> <circle cx='30' cy='30' r='20' style='stroke:black; fill:none' /> <circle cx='80' cy='30' r='20' style='stroke-width:5;stroke:black; fill:none' /> <ellipse cx='30' cy='80' rx='10' ry='20' style='stroke:black; fill:none' /> <ellipse cx='80' cy='80' rx='20' ry='10' style='stroke:black; fill:none' /> </svg> <!--多个 多边形,组合--> <svg width='200' height='200' xmlns='http://wwww.w3.org/2000/svg'> <!--平等四边形--> <polygon points='15,10 55,10 45,20 5,20' style='fill:red; stroke: black;' /> <!--五角星--> <polygon points='35,37.5 37.9,46.1 46.9,46.1 39.7,51.5 42.3,60.1 35,55 27.7,60.1 30.3,51.5 23.1,46.1 32.1,46.1' style='fill: #ccffcc; stroke: green;' /> <!--不规则图形--> <polygon points='60 60, 65,72 80 60, 90,90 72,85 50,95' style="fill: yellow; fill-opacity:.5; stroke:black" /> </svg> <!--五角星--> <svg width='200' height='200' xmlns='http://wwww.w3.org/2000/svg'> <polygon points='48,16 16,96 96,48 0,48 80,96' style='fill:none; stroke: black;' /> </svg> <!--填色五角星--> <svg width='200' height='200' xmlns='http://wwww.w3.org/2000/svg'> <polygon points='48,16 16,96 96,48 0,48 80,96' style='fill-rule: nonzero; fill:yellow; stroke: black;' /> <polygon points='148,16 116,96 196,48 100,48 180,96' style='fill-rule: evenodd; fill:red; stroke: black;' /> </svg> <!--心电图--> <svg width='200' height='200' xmlns='http://wwww.w3.org/2000/svg'> <polyline points="5,20 20,20 25,10 35,30 45,10 55,30 65,10 74,30 80,20 95,20" style="stroke:black; stroke-width:3; fill:none" /> </svg> <!--家--> <svg width='240' height='240' xmlns='http://wwww.w3.org/2000/svg'> <title>欢乐一家人</title> <desc>一家人在一起就是简单幸福的了</desc> <g id='house' style='fill:none; stroke:black'> <desc>房子</desc> <rect x='6' y='50' width='60' height='60' /> <polyline points='6 50, 36 9, 66 50' /> <polyline points='36 110, 36 80, 50 80, 50 110' /> </g> <g id='man' style='fill:none; stroke:green'> <desc>男人</desc> <circle cx='85' cy='56' r='10' /> <line x1='85' y1='66' x2='85' y2='80' /> <polyline points='76 104, 85 80, 94 104' /> <polyline points='76 70, 85 76, 94 70' /> </g> <g id='woman' style='fill:none; stroke:red'> <desc>女人</desc> <circle cx='110' cy='56' r='10' /> <polyline points='110 66, 110 80, 100 90, 120 90, 110 80' /> <line x1='104' y1='104' x2='108' y2='90' /> <line x1='112' y1='90' x2='116' y2='104' /> <polyline points='101 70, 110 76, 119 80' /> </g> </svg> <!--使用模板--> <svg width='240' height='240' viewBox='0 0 240 240' xmlns='http://wwww.w3.org/2000/svg'> <title>欢乐一家人</title> <desc>一家人在一起就是简单幸福的了</desc> <defs> <g id='house' style='stroke:black'> <desc>房子</desc> <rect x='0' y='41' width='60' height='60' /> <polyline points='0 41, 30 0, 60 41' /> <polyline points='30 110, 30 71, 44 71, 44 101' /> </g> <g id='man' style='fill:none; stroke:green'> <desc>男人</desc> <circle cx='10' cy='10' r='10' /> <line x1='10' y1='20' x2='10' y2='44' /> <polyline points='1 58, 10 44, 19 58' /> <polyline points='1 24, 10 30, 19 24' /> </g> <g id='woman' style='fill:none; stroke:red'> <desc>女人</desc> <circle cx='10' cy='10' r='10' /> <polyline points='10 20, 10 34, 0 44, 20 44, 10 34' /> <line x1='4' y1='58' x2='8' y2='44' /> <line x1='12' y1='44' x2='16' y2='58' /> <polyline points='1 24, 10 30, 19 24' /> </g> <g id='couple'> <desc>夫妻</desc> <use xlink:href='#man' x='0' y='0' /> <use xlink:href='#woman' x='25' y='0' /> </g> </defs> <!--FIXME 此处,显示上,仍然有问题??????--> <use xlink:href='#house' x='0' y='0' style='fill:#cfc' /> <!--FIXME 此处,显示上,仍然有问题??????--> <use xlink:href='#couple' x='70' y='40' /> <!--FIXME 此处,显示上,仍然有问题??????--> <use xlink:href='#house' x='120' y='0' style='fill:#99f' /> <!--FIXME 此处,显示上,仍然有问题??????--> <use xlink:href='#couple' x='190' y='40' /> </svg> <!--另外一种模板--> <svg width='240' height='240' viewBox='0 0 240 240' xmlns='http://wwww.w3.org/2000/svg'> <defs> <symbol id="circle" viewBox="0 0 100 100" preserveAspectRatio="xMinYMin meet"> <circle cx="50" cy="50" r="50"></circle> </symbol> <symbol id="triangle" viewBox="0 0 100 100" preserveAspectRatio="xMaxYMax slice"> <polygon points="0 0, 100 0, 50 100"></polygon> </symbol> </defs> <g stroke="grey" fill="none"> <rect x="0" y="0" width="50" height="100"></rect> <rect x="100" y="0" width="50" height="100"></rect> </g> <use xlink:href="#circle" width="50" height="100" fill="red"></use> <use xlink:href="#triangle" width="50" height="100" fill="red" x="100"></use> </svg> <svg width='310' height='310' viewBox='0 0 310 310' xmlns='http://wwww.w3.org/2000/svg'> <ellipse cx='154' cy='154' rx='150' ry='120' style='fill: #999'/> <ellipse cx='152' cy='152' rx='150' ry='120' style='fill: #999' /> <image xlink:href='../public/image/fabric_test.jpg' x='72' y='92' width='160' height='120' /> </svg> </body> </html>