请在chrome浏览器 ( 以及mac ) 下获得最佳体验 -- 方潇仪
CSS
Canvas
SVG
image.svg
<image>
background-image
xml
inline SVG

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" class="bird" width="100"  viewBox="0 0 64.3 72.2">
    <path class="wing" d="M41.6,37.6c-0.5-0.1-1.1,0.2-1.2,0.8c-0.1,0.5,0.2,1.1,0.8,1.2c1.3,0.3,2.5,2.2,2.9,4.3
    c0.2,0.9-0.3,2.3-1.1,3.4c-0.9,1.1-2,1.9-2.9,2c-1.3,0.1-2.3-2.5-2.6-4c0-0.1,0-0.2-0.1-0.3c-0.1-0.5-0.7-0.9-1.2-0.8
    c-0.5,0.1-0.9,0.6-0.8,1.2c0,0.1,0,0.1,0.1,0.3c0.2,1.4-0.2,3-1.2,4.3c-1,1.4-2.5,2.3-3.9,2.4c-0.6,0.1-1-0.1-1.4-0.4
    c-0.9-0.9-1-2.9-0.9-3.7c0-0.5-0.3-0.9-0.8-1c-0.5-0.1-1,0.2-1.1,0.6c0,0-1.5,4.1-4.4,4.9c-1,0.3-1.4-0.1-1.6-0.2
    c-1-0.8-1.1-3.3-1.1-4.1c0-1.4,1.8-2.6,2.6-3c0.5-0.3,0.7-0.9,0.4-1.3c-0.3-0.5-0.9-0.7-1.3-0.4c-0.4,0.2-3.7,2-3.7,4.9
    c0.1,2,0.3,4.4,1.9,5.6c0.6,0.4,1.3,0.7,2.1,0.7c0.4,0,0.8-0.1,1.2-0.2c1.9-0.5,3.3-1.9,4.3-3.2c0.2,0.7,0.6,1.4,1.1,1.9
    c0.8,0.7,1.8,1.1,2.9,1c2-0.2,4-1.4,5.4-3.2c0.4-0.6,0.8-1.2,1-1.8c0.8,1.1,1.8,2,3.3,1.9c1.5-0.2,3.1-1.2,4.3-2.8
    c1.2-1.6,1.8-3.4,1.5-4.9C45.5,40.5,43.7,38,41.6,37.6z" />
    <path class="eye" d="M40,27.5L40,27.5c0.2,0,0.5,0,0.7-0.1c1-0.2,2-0.9,2.5-1.9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5C54.9,35.6,53.2,47.1,50.4,52.3z M55.8,33.3
    c0-1.4-0.1-2.9-0.2-4.3l6.2,1.1C59.7,31.7,57.7,32.7,55.8,33.3z" />
</svg>
            
                
<svg class="svg__vector-intro" viewBox="0 0 960 200">
    <rect x="40.2" y="25.3" width="150" height="150"/>
<circle cx="354.4" cy="100.3" r="75"/>
<polygon points="593.6,25.3 617.9,74.7 672.4,82.6 633,121.1 642.3,175.3 593.6,149.7 544.8,175.3 554.1,121.1 514.7,82.6 569.2,74.7 "/>
<path d="M923,107.3C11.5,41.5 51.2,38.8 66.5,29.5C829,120 836.9,77.9 810,63.3C21.5 11.6 59 5 67.5,33.5"/> </svg>
SVG Special Attribute
  • fill
  • fill-opacity
  • stroke
  • stroke-opacity
  • stroke-dasharray
  • stroke-dashoffset
  • stroke-linecap
  • stroke-width
  • marker
  • marker-start
  • alignment-baseline
  • text-anchor
  • flood-color
  • flood-opacity
  • stop-color
  • stop-opacity
  • ...
LINE DRAWING描线
stroke-dasharray:00
stroke-dashoffset: 0
path

<svg width="800" viewBox="0 0 581 98">
    <path id="path"
          d="M62.9 14.9....2 11 33 17.3 36 21.1-37.6 42.8 6.2 72.9z"
          stroke="#0171bb" stroke-width="2" />
</svg>
            

var path = document.getElementByID("path");
path.getTotalLength();
            
rect, circle, polygon...
转换
计算
Elastic Stroke
MORPHING变形
                
                    <path d="
M 0 0 C 50 0 50 0 100 0 C 100 50 100 50 100 100 C 50 100 50 100 0 100
C 0 50 0 50 0 0
" />
                
Snap.svg.js

<svg id="js-svg" width="100" height="100">
    <path id="path1" d="M 0 0 C 50 0 50 0 100 0 ...C 0 50 0 50 0 0" />
</svg>
            

//javascript
var paper = new Snap("#js-svg");
var path = paper.select("#path1");
path.animate({
   d: "M 25,50 C 37.5,25 37.5,25 ... 12.5,75 12.5,75 25,50 Z"
},1000);
            

FOLLOW THE PATH路径运动
svg textPath元素可以让文字随着指定路径排列

<defs>
    <path id="p1"
    d="M62.9 14.9c-25-7.74-56.6 4.8-60.4 24.3-3.73 19.6 21.6...">
    </path>
</defs>

<text>
    <textPath xlink:href="#p1" textLength="400"  startOffset="250">
    svg textPath元素可以让文字随着指定路径排列
    </textPath>
</text>
                
SMIL
Snap.svg.js

    Snap.animate(0, followPath.length, function (val) {

        //获取路径上相应长度点的信息
        var movePoint = objectPath.path1.getPointAtLength(val);

        //设定元素位置为相应点的坐标
        objectPath.cicle.attr({
            cx: movePoint.x,
            cy: movePoint.y
        });

    }, mina.easeinout, 4500);
            

                Element.getPointAtLength(length);

                {
                    x: x coordinate, //x坐标
                    y: y coordinate, //y坐标
                    alpha: angle of derivative //切线角度
                }
            
PATTERN图案填充

    <!--define patterns 定义图案-->
    <defs>
        <pattern id="ashano-EU" width="64" height="64">
            <path d="M50 50c0-5.523 4.477-10 10-10s17 10-10 10..." />
        </pattern>
    </defs>

    <rect width="100%" height="100%" fill="url(#ashano-EU)" />
                
PATTERN
FILTER滤镜

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
    <defs>
        <filter id="filter-name">
            ...
            <!-- insert filters here -->
            ...
        </filter>
        ...
    </defs>
</svg>
            

.selector{
    filter: url('#filter-name');
    filter: url('filters.svg#filter-name');
}
            
SVG Filter
  • feOffset
  • feGaussianBlur
  • feBlend
  • feColorMatrix
  • feComponentTransfer
  • feComposite
  • feConvolveMatrix
  • feDiffuseLighting
  • feDisplacementMap
  • feFlood
  • feImage
  • feMerge
  • feMorphology
  • feSpecularLighting
  • feTile
  • feTurbulence
  • feDistantLight
  • fePointLight
  • ...

<filter id="drop-shadow">
    <feGaussianBlur in="SourceGraphic" stdDeviation="7" result="shadow" />
    <feOffset in="shadow" dx="3" dy="4" result="shadow" />
                ...
    <feColorMatrix in="shadow" mode="matrix" values="0 0 0 0 0
                0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0" result="shadow" />
    <feBlend in="SourceGraphic" in2="shadow" />
</filter>
            
Pansen! Extruded STRIPES! Off Set. Torn Out Outlined Noizeee! Beveled
GaussianBlur

 <defs>
    <filter id="fuzzy">
        <feGaussianBlur in="SourceGraphic" stdDeviation="10,0"/>
    </filter>
 </defs>
            
4
3
2
1

<defs>
    <filter id="goo">
        <feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" />
        <feColorMatrix in="blur" mode="matrix" values="1 0 ... 18 -7" result="goo" />
        <feBlend in="SourceGraphic" in2="goo" />
    </filter>
</defs>
                
参考资料
SVG基础知识
SVG动画综述
参考资料
SVG动画知识点
THANKS