svg

svg的一些形狀:

矩形:

<rect x="20" y="20" width="250" height="250"
style="fill:blue;stroke:pink;stroke-width:5;
fill-opacity:0.1;stroke-opacity:0.9"/>

圓形:

<circle cx="100" cy="50" r="40" stroke="black"
stroke-width="2" fill="red"/>

線條:

<line x1="0" y1="0" x2="300" y2="300"
style="stroke:rgb(99,99,99);stroke-width:2"/>

多邊形:

<polygon points="220,100 ,300,210 ,170,250"
style="fill:#cccccc;
stroke:#000000;stroke-width:1"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords"content=""/>
<meta name="description" content="本篇網頁的概述,一段話,對網站的進一步描述"/>
<meta name="author"  content="網頁作者的資料">
<meta name="robots" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標題文檔</title>
<script>
window.οnlοad=function  () {
var one=document.getElementById("one");
var svg=one.getSVGDocument();//獲取svg對象
var svgdoc=svg.documentElement;
var po=svgdoc.getElementsByTagName("polygon")[0];//獲取svg中包含的polygon標籤對象
var angle=0;
 //po.style.strokeWidth=10;修改polygon標籤中的樣式屬性
 //alert(po.setAttribute("points","0,0,50,0,50,50"));獲取points標籤中的樣式屬性值
 setInterval(function  () {
angle+=0.1;
var str=po.getAttribute("points");//獲取points標籤中的樣式屬性值
var arr=str.split(",");
var newstr="";
for (var i=0; i<arr.length; i++) {
var num=parseInt(arr[i]);//把字符串轉爲數值類型
 num+=10*Math.random()*Math.sin(angle);//限制svg的顯示範圍,防止svg圖片跑出顯示區域
 newstr+=num+",";
}
newstr=newstr.substr(0,newstr.length-1);//去掉最後拼接上的逗號

po.setAttribute("points",newstr);//重新設置points標籤中的樣式屬性值

 },50)
}
</script>
</head>

<body>

<embed src="svg.svg" width="600" height="600" 
type="image/svg+xml"
pluginspage="http://www.adobe.com/svg/viewer/install/" id="one"/><!--引入svg圖片-->
<!--
<object data="rect.svg" width="300" height="100" 
type="image/svg+xml"
codebase="http://www.adobe.com/svg/viewer/install/" />

<iframe src="svg.svg" width="300" height="100">
</iframe>

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="190">
<polygon points="220,100 ,300,210 ,170,250"
style="fill:#cccccc;
stroke:#000000;stroke-width:5"/><!--畫svg圖片-->
</svg>
-->
</body>
</html>


發佈了96 篇原創文章 · 獲贊 4 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章