svg 和 canvas的区别
工具canvassvg
绘图类型位图矢量图缩放失真不失真颜色细节丰富单调运用领域图片、游戏图标、地图、统计图内容JS绘图每个图形都是标签事件绑定只能在canvas标签上绑定非常方便
svg 矢量图
绘制的元素标签包含在svg内部
分组标签
在分组中的元素可以自动继承公共属性或样式
<svg><g>有相同属性的元素
</g></svg>
动态创建svg相关的标签
var oRect
= document
.createElementNS('http://www.w3.org/2000/svg', 'rect');
oRect
.setAttribute('属性名','属性值');
oRect
.getAttribute('属性名');
矩形+多边形
<svg><rect width="100" height="100" x='100' y ='100' fill=''>
</rect></svg>
<svg><polygon points="x1,y1 x2,y2 x3,y3 ...." stroke =''>
</polygon></svg>
绘制圆形+椭圆
<svg><circle cx="圆心x轴坐标" cy="圆心y轴坐标" r ="半径" fill="填充色" fill-opacity="颜色透明度">
</circle></svg>
<svg><ellipse cx = 'x轴上的圆心' cy='y轴上的圆心' rx='x轴上的半径' ry='y轴上的半径'>
</ellipse></svg>
绘制直线+折线
<svg><line x1="" y1="" x2="" y2="" stroke="red" ></line></svg>
<svg><polyline points="x1,y1 x2,y2 x3,y3 ...." stroke =''>
</polyline></svg>
绘制文本+图像
<svg><text x="" y="" font-size="" aligment-baseline="before-edge">文本内容
</text></svg>
<svg><image width="" height="" xlink:href="xxx.jpg" x="" y=""></image></svg>
渐变
线性渐变
<svg width="600" height="400" id="svg">
<defs>
<linearGradient id="lg1" x1="0" y1="0" x2="0" y2="100%">
<stop stop-color="red" offset="0%"></stop>
<stop stop-color="orange" offset="10%"></stop>
<stop stop-color="green" offset="20%"></stop>
<stop stop-color="pink" offset="30%"></stop>
<stop stop-color="blue" offset="50%"></stop>
<stop stop-color="gray" offset="60%"></stop>
<stop stop-color="cyan" offset="70%"></stop>
<stop stop-color="gold" offset="80%"></stop>
<stop stop-color="purple" offset="90%"></stop>
<stop stop-color="yellow" offset="100%"></stop>
</linearGradient>
</defs>
<rect x="100" y ="100" width="200" height="100" style="fill: url(#lg1);">
</rect>
<circle cx="300" cy="300" r ="50" fill="url(#lg1)">
</circle>
</svg>
辐射性渐变 贝塞尔路径
暂待
特效对象 – 滤镜(filter)
<svg width="600" height="400" id="svg">
<defs>
<filter id="fil1"> <feGaussianBlur stdDeviation="3"></feGaussianBlur>
</filter>
</defs>
<text x="50" y="100" font-size="70" filter="url(#fil1)">我和我的祖国
</text>
</svg>