有时因为一些需要,要在SVG图里加按钮之类的东西,让按钮显示在SVG图上,一般有2种办法:
1、比较常见的是网上所说的在embed标签里加wmode="Transparent"的属性,这种办法的好处是可以随意用CSS+DIV给按钮在网页中定想要的位置说。例子:
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
margin:0 auto;
font-size:12px;
color:#333333;
width:100%;
}
.button_div{
margin:0 auto;
width:100%;
height:500px;
position:relative;
}
.butt{
position:absolute;
top:50px;
left:30px;
}
</style>
<script type="text/javascript">
function Button4_onclick() {
//代码
}
</script>
<div class="button_div">
<embed name="svg" id="svg" type="image/svg+xml" src="PIC.svgz" width="800px" wmode="Transparent"
height="600px"></embed>
<div class="butt1">
<input id="Button4" οnclick="Button4_onclick()" type="button" value="刷新" />
<br />
</div>
</div>
在这里,<div class="butt1">相对<div class="button_div">定位了,按钮浮动在SVG图上。可以定位于图上的任何位置,也不用设置优先级,而且JS事件写起来也很方便。
2、也可以在SVG图里画好按钮,写好文字,之后在文字的<text>标签里写JS事件,例子:
<a xlink:href="javascript:Button4_onclick()" id="a237">刷新</a>
然后引用的页面上写JS的事件(比如这个的:Button4_onclick())就可以。