svg 文件可通过以下标签嵌入 HTML 文档:<embed>、<object>或者<iframe>。

复制代码 代码如下:

<embed src=”rect.svg” width=”300″height=”100″

type=”image/svg+xml”

pluginspage=”http://www.adobe.com/svg/viewer/install/”/>

pluginspage 属性指向下载插件的 URL。

复制代码 代码如下:

<object data=”rect.svg”width=”300″ height=”100″

type=”image/svg+xml”

codebase=”http://www.adobe.com/svg/viewer/install/”/>

<iframe src=”rect.svg” width=”300″height=”100″>

</iframe>

在这三个中<iframe>是比较早期的标签,现在用的比较的少了。用的较多的还是<embed>标签。

同时我们也可以将svg直接写入HTML文件中:

这样的话需要先引入SVG的dtd文件:

复制代码 代码如下:

<?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>标签中填入需要的代码:

复制代码 代码如下:

<svg width=”100%” height=”100%” version=”1.1″

xmlns=”http://www.w3.org/2000/svg” onclick=”ccc();”>

<ellipse cx=”240″ cy=”100″ rx=”220″ ry=”30″

style=”fill:yellow”/>

<ellipse cx=”220″ cy=”100″ rx=”190″ ry=”20″ id=”w1″

style=”fill:white”/>

</svg>

如果svg代码在html中,我们就更容易写javascript来控制图形的变换:

复制代码 代码如下:

<script type=”text/javascript”>

function ccc(){

var a = document.getElementById(“w1”);

a.style.fill=”red”;

a.setAttribute(“cx”, “150”); //设置值

a.setAttribute(“ry”, “50”); //设置值

}

</script>

下面介绍一些svg的预定义形状元素

矩形 <rect>

圆形 <circle>

椭圆 <ellipse>

线 <line>

折线 <polyline>

多边形 <polygon>

路径 <path>



声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。