svg

作者: 六月太阳花 | 来源:发表于2017-01-12 10:29 被阅读0次

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);  

相关文章

  • Android图片之svg

    1.SVG是什么2.SVG优点3.SVG使用4.获取SVG5.封装使用6.SVG动画 1.SVG是什么? SVG(...

  • SVG的使用

    SVG图片 一. SVG介绍 1.1. SVG概念解析 SVG全称: Scalable Vector Graphi...

  • 资源

    SVG svg icon 对应git(node.js写的) svg animation study svg cs...

  • (第六天)HTML5之SVG的了解与使用&Web数据存储

    SVG 什么是SVG? SVG 指可伸缩矢量图形 (Scalable Vector Graphics) SVG 用...

  • svg standalone

    简单的 SVG 实例 一个简单的SVG图形例子: 这里是SVG文件(SVG文件的保存与SVG扩展): "http:...

  • SVG学习笔记

    SVG学习笔记 简介 SVG使用XML来描述二维图形和绘图程序的语言。 SVG形状 SVG在HTML页面 SVG ...

  • SVG

    Menu SVG 实例 SVG 形状 SVG 实例 SVG 的 用来创建一个圆。cx 和 cy ...

  • SVG简介及其用法

    一、SVG - 基础 1.什么是SVG 2.SVG的优势 3.SVG与canvas的区别 4.用途 5.svg再将...

  • svg实例

    一个简单的SVG图形例子: 这里是SVG文件(SVG文件的保存与SVG扩展): SVG 代码解析: 第一行包含了 ...

  • SVG用法

    常见引入svg的方法 .svg文件的常见结构: html页面中绘制svg的常见方法: 关于SVG的viewBox:...

网友评论

      本文标题:svg

      本文链接:https://www.haomeiwen.com/subject/lsddbttx.html