!!!常用SVG代碼


http://www.w3school.com.cn/svg/svg_examples.asp  svg實例

http://www.w3school.com.cn/svg/svg_reference.asp   svg元素   2015-6-25

http://www.cnblogs.com/qq21270/p/3421491.html   js控制svg例子

http://isux.tencent.com/16292.html   使用SVG中的Symbol元素制作Icon 2015-4-1

http://www.w3cplus.com/svg/why-the-svg-filter-is-awesome.html   SVG濾鏡的藝術以及它為什么這么棒  2015-6-25

 

直接放在網頁里:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<style type="text/css">
svg{width:600px;height:400px;border:1px solid #999;}
.abbbb{fill:#ffa;}/*css可控制svg*/
.abccc{fill:#f90;font-size:80px;font-family:"微軟雅黑";}
</style>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <circle cx="50%" cy="50%" r="200" fill="#999999" class="abbbb"/>
    <text x="0" y="50%" class="abccc" style="font-family:'微軟雅黑';font-size:24;">畫個圈圈詛咒你</text> 
</svg>
</body>
</html>

以圖象方式引入:

<style type="text/css">
.img1{width:400px;height:400px;border:1px solid #999;}
</style>
<img src="1.svg" class="img1">

 注意:要想正常顯示svg效果需要ie10及以上。(svg ie8及以下不支持。svg濾鏡 ie9及以下不支持)

 

優雅降級:  http://www.zhangxinxu.com/wordpress/2013/09/svg-fallbacks/

<svg width="96" height="96">
  <image xlink:href="http://www.zhangxinxu.com/study/image/svg/svg.svg" src="http://www.zhangxinxu.com/study/image/svg/svg.png" width="96" height="96" />
</svg>

 

 

=============================================================

 

圓形

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg">
<!-- <circle cx="50%" cy="50%" r="48%" stroke="#cc0000" stroke-width="2" fill="#ff0000"/> -->
<circle cx="50%" cy="50%" r="48%" style="stroke:#ff00ff;stroke-width:3;fill:#fafafa"/>
</svg>

 

圓形(style設定顏色):

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" width="100%" height="100%" xml:space="preserve">
    <g>
        <!-- <circle fill-rule="evenodd" clip-rule="evenodd" fill="#fafafa" cx="50%" cy="50%" r="50%" style="stroke:#fcfcfc;stroke-width:2"/> -->
        <circle fill-rule="evenodd" clip-rule="evenodd"  cx="50%" cy="50%" r="48%" style="stroke:#ff0000;stroke-width:3;fill:#fafafa"/>
    </g>
</svg>

 

圓形(circle圓形、clipPath剪裁)

http://www.zhangxinxu.com/wordpress/2014/12/css3-svg-clip-path/   CSS3/SVG clip-path路徑剪裁遮罩屬性簡介

<svg>
    <defs>
      <clipPath id="clipPath">
          <rect x="0" y="0" width="80" height="80" />
      </clipPath>
    </defs>
    <circle cx="60" cy="60" r="50" fill="#34538b" clip-path="url(#clipPath)" />
</svg>

 

手機圖標:目錄(三橫線)

 

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="16" height="16" version="1.1" xmlns="http://www.w3.org/2000/svg">
<line x1="0" y1="1" x2="16" y2="1" style="stroke:#ffffff;stroke-width:2"/>
<line x1="0" y1="8" x2="16" y2="8" style="stroke:#ffffff;stroke-width:2"/>
<line x1="0" y1="15" x2="16" y2="15" style="stroke:#ffffff;stroke-width:2"/>
</svg>

 

 

 

polyline

 對勾(polyline 一系列連接的直線)

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg">
<polyline points="3,14 8,19 20,7" style="fill:white;stroke:red;stroke-width:5"/>
</svg>


<img src="ok.svg" width="24" height="24">

 

多邊形(倒三角)(polyline 一系列連接的直線)

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg width="15" height="9" version="1.1" xmlns="http://www.w3.org/2000/svg">
<polygon points="0,0 15,0 7,8" style="fill:#f94325;"/>
</svg>

 

半星(五角星)(polyline 一系列連接的直線)

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100" height="100" version="1.1" xmlns="http://www.w3.org/2000/svg">
<polygon points="50,2 61,36 96,36 67,57 79,92 50,71  20,92 32,57 2,36  39,36 50,2" style="fill:#ff0000;stroke:#ff0000;stroke-width:6;"/>
<polygon points="50,2 61,36 96,36 67,57 79,92 50,71  50,2" style="fill:#ffffff;"/>
</svg>

 

 文字(text)

<style type="text/css">
svg{width:400px;height:400px;border:1px solid #999;}
.abc{fill:#f0f;}
</style>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<text x="0" y="15" fill="red" font-size="20" class="abc">svg里面顯示文字。注意這段文字是可以受網頁中的css控制的</text>
</svg>

路徑文字(text、 path)

<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
    $("#SVG222").click(function(){
        console.dir($(".abccc"));
    });
});
</script>
<style type="text/css">
svg{width:600px;height:400px;border:1px solid #999;}
.abccc{fill:#f90;font-size:32px;font-family:"微軟雅黑";}
</style>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="SVG222">
    <path id="mypath" d="M50 100Q350 50 350 250T450 250" style="fill:none;stroke:red;stroke-width:5;" />
    <text x="10" y="20" class="abccc">
        <textPath xlink:href="#mypath">路徑文字。注意:點擊svg后,可以通過console.dir()觀看text的屬性</textPath>
    </text>
</svg>

 

 

 

 

輪播圖,向左、向右大按鈕

向左

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="93" height="93" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle cx="50%" cy="50%" r="48%" stroke="#9e9e9e" stroke-width="2" fill="#ffffff"/>
<polyline points="52,21 33,47 52,73 33,47" style="stroke:#9e9e9e;stroke-width:3"/>
</svg>

向右

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="93" height="93" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle cx="50%" cy="50%" r="48%" stroke="#9e9e9e" stroke-width="2" fill="#ffffff"/>
<polyline points="41,21 60,47 41,73 60,47" style="stroke:#9e9e9e;stroke-width:3"/>
</svg>

 

畫曲線

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 100">
  <!-- 
  fill屬性是否填充
  stroke為繪制,顏色#AAAAAA
  stroke-width為繪制線的粗細
  d是具體數據,這里看到的數據代表了坐標,以及折線等等,可以使用工具生成
  -->
  <path fill="none"
            stroke = "#AAA"
            stroke-width = "2"
            d = "M62.9 14.9c-25-7.74-56.6 4.8-60.4 24.3-3.73 19.6 21.6 35 39.6 37.6 42.8 6.2 72.9-53.4 116-58.9 65-18.2 191 101 215"
  />
</svg>

 

http://www.cnblogs.com/qq21270/p/4048383.html   中國地圖

 

閱讀:

http://www.zhangxinxu.com/wordpress/2014/07/introduce-svg-sprite-technology/   未來必熱:SVG Sprite技術介紹 zxx

http://www.zhangxinxu.com/wordpress/2014/07/svg-sprites-fill-color-currentcolor/   SVG圖標顏色文字般繼承與填充 zxx

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM