在SVG图里加按钮

有时因为一些需要,要在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())就可以。

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值