前端笔墨

进入SVG

2018-10-07  本文已影响7人  桃花島主

SVG-简单示例

code

rect


code

circle


code

ellipse


code

line


code

polyline


code

polygon


code

填充、描边、变换

基本操作API

document.createElementNS(ns, tagName)
element.appendChild(childElement)
element.setAttribute(name, value)
element.getAttribute(name)

svg综合运用的小例子svg-editor

SVG的世界、视野、视窗

定义

描述

<svg xmlns="..."
width="800" height="600" viewBox="0 0 400 300" preserveAspectRatio="xMidYMid meet">
<!--SVG Content-->
</svg>

视窗

g演变过程

锤子-1


SVG中的图形分组

svg坐标系

4个坐标系

坐标变换

线性变换

旋转

缩放

线性变换列表

transform属性

rotate(<deg>)
translate(<x>,<y>)
scale(<sx>,<sy>)
matrix(<a>,<b>,<c>,<d>,<e>,<f>)

调色面板

在SVG中应用颜色

<rect fill="rgb(255,0,0)" opacity="0.5" />
<rect stroke="hsla(0,50%,60%,0.5) />"

线性渐变

<svg xmlns="http://www.w3.org/2000/svg" width="400" height="350">
  <defs>
    <linearGradient id="grad1" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="1" y2="1">
      <stop offset="0" stop-color="#1497FC" />
      <stop offset="0.5" stop-color="#A469BE" />
      <stop offset="1" stop-color="#FF8C00" />
    </linearGradient>
  </defs>
  <rect x="100" y="100" fill="url(#grad1)" width="200" height="150" />
</svg>

<svg xmlns="http://www.w3.org/2000/svg" width="400" height="350">
  <defs>
    <linearGradient id="grad1" gradientUnits="userSpaceOnUse" x1="100" y1="100" x2="150" y2="150">
      <stop offset="0" stop-color="#1497FC" />
      <stop offset="0.5" stop-color="#A469BE" />
      <stop offset="1" stop-color="#FF8C00" />
    </linearGradient>
  </defs>
  <rect x="100" y="100" fill="url(#grad1)" width="200" height="150" />
</svg>

code

径向渐变

<svg xmlns="http://www.w3.org/2000/svg" width="400" height="350">
  <defs>
    <radialGradient id="grad2" cx="0.5" cy="0.5" r="0.5" fx="0.6" fx="0.3">
      <stop offset="0" stop-color="rgb(20,151,252)" />
      <stop offset="0.5" stop-color="rgb(164,105,190)" />
      <stop offset="1" stop-color="rgb(255,140,0)" />
    </radialGradient>
  </defs>
  <rect x="100" y="100" fill="url(#grad2)" width="200" height="150" />
</svg>

笔刷

<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="500">
  <defs>
    <pattern id="p1" x="0" y="0" width="0.2" height="0.2">
      <circle cx="10" cy="10" r="5" fill="red"></circle>
      <polygon points="30 10 60 50 0 50" fill="green"></polygon>
    </pattern>
  </defs>
  <rect x="100" y="100" fill="url(#p1)" width="800" height="300" stroke="blue" />
</svg>

code


项目代码
上一篇 下一篇

猜你喜欢

热点阅读