svg

svg:画图-->矢量图 位图
兼容ie9+ chrome FF

    <svg width="800" height="600">
        <line x1="100" y1="100" x2="300" y2="300" stroke="red" stroke-width="20"></line>
    </svg>

默认中心的是左上角

        需用要transform-origin:center center;改变 
    <svg width="800" height="600">
        <line x1="100" y1="100" x2="300" y2="100" transform="rotate(30,center,center)"></line>
    </svg>

矩形:rect

<svg width="800" height="600">
        <rect x="100" y="100" width="200" height="200"></rect>
    </svg>

圆:circle

<svg width="800" height="600">
        <circle cx="200" cy="200" r="100" stroke="#f00" stroke-width="20" stroke-opacity="0.5"></circle>
    </svg>

椭圆:ellipse

<svg width="800" height="600">
        <ellipse cx="200" cy="200" rx="100" ry="150"></ellipse>
    </svg>
svg属性   
    stroke
    stroke-width
    fill
    fill="none"         去除填充色
    fill-opacity
    stroke-opacity

stroke-lineCap=""       端点样式
    butt round square
<svg width="800" height="600">
        <line x1="100" y1="100" x2="300" y2="300" stroke="red" stroke-width="20" stroke-lineCap="butt"></line>
        <line x1="100" y1="200" x2="300" y2="400" stroke="red" stroke-width="20" stroke-lineCap="round"></line>
        <line x1="100" y1="300" x2="300" y2="500" stroke="red" stroke-width="20" stroke-lineCap="square"></line>
    </svg>

stroke-lineJoin="" 链接点样式
miter round bevel

<svg width="800" height="600">
        <rect x="100" y="100" width="200" height="200" stroke="red"stroke-width="20" stroke-lineJoin="miter"></rect>
    </svg>

虚线:stroke-dasharray=""

<svg width="800" height="600">
        <line x1="100" y1="100" x2="500" y2="500" stroke="red" stroke-width="20" stroke-dasharray="10,5,15,20"></line>
    </svg>

svg运动:transtorm

创建标签
document.createElement() 创建html元素
document.createElementNS(命名空间,标签名)这个才是最靠谱的创建方式

var oS=document.querySelector('svg'); 
    var oRect=document.createElement('rect'); 
    oRect.setAttribute('x',100);
    oRect.setAttribute('y',100);    
    oRect.setAttribute('width',200);    
    oRect.setAttribute('height',200);


var oS=document.querySelector('svg');
    
    var oRect=document.createElementNS('http://www.w3.org/2000/svg','rect');
    
    oRect.setAttribute('x',100);
    oRect.setAttribute('y',100);    
    oRect.setAttribute('width',200);    
    oRect.setAttribute('height',200);
    
    oS.appendChild(oRect);  

路径:path
d="M L Z"
M moveTo
L lineTo
Z 闭合路径

<svg width="800" height="600">
        <path d="M100 200 L300 100 L400 200 Z"></path>
    </svg>

<svg width="800" height="600">
        <path d="M100,200 300,100 400,200 Z"></path>
    </svg>

<svg width="800" height="600">
        <path d="M100 200,L300 100,L400 200,Z"></path>
    </svg>

属性:

var oLine=document.querySelectorAll('line')[1]; 
    oLine.addEventListener('click',function (){
        alert(this.getAttribute('y1'));
    },false);
oLine.addEventListener('click',function (){
        this.setAttribute('y1',200);
    },false);  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、什么是SVG? SVG指可伸缩矢量图形(Scalable Vector Graphics); SVG用来定义用...
    清心挽风阅读 1,424评论 1 3
  • SVG API: SVG是一种可缩放矢量图形,一种二维图形表示语言 与canvas不同的是,在浏览器的开发工具中能...
    Iris_mao阅读 1,042评论 0 5
  • 一:什么是SVG? 对于SVG的定义如下: ①:SVG 指的是可伸缩矢量图形 (Scalable Vector G...
    GreenHand1阅读 842评论 0 1
  • 上个项目用到svg实现一个水流的动画,鉴于没学习几天,所以懂的也不多,就此分享一下。首先svg是什么,svg可缩放...
    会飞的猪l阅读 4,192评论 0 5
  • SVG 图片是一种可支持任意缩放的图片格式,使用 xml 定义,使用 canvas 中 path 路径来完成绘制,...
    前行的乌龟阅读 3,985评论 1 5