我正在使用snap.svg我有index.html
<!Doctype>
<html>
<head>
<title>MAP_TEST</title>
<meta charset="utf-8">
<script type = "text/javascript" src = "JS/jquery.js"></script>
<script type = "text/javascript" src = "JS/init.js"></script>
<script type = "text/javascript" src = "JS/snap.svg.js"></script>
</head>
<body>
<div class="comm_cont">
<div id = "svgborder">
<svg id = 'svgmain'></svg>
</div>
</div>
</body>
</html>
还有init.js
$( document ).ready(function() {
var s = Snap("#svgmain");
var g = s.group();
Snap.load("SVGFILES/3k1e-test.svg",function(lf)
{
g.append(lf);
//trying to load picture... Scale button in future
$('<img />', {
src: 'PNG/plus.png',
width: '30px',
height: '30px',
id: 'buttoninrk'
}).appendTo($('.comm_cont'));
//this button must be on picture
//but in front of the picture svg element
//And i can't click the button
});
});
我使用#svgborder和#buttoninkr的z-indexes玩,但是它没有帮助我。如何将按钮放在svg元素前面?
#buttoninkr, #svgborder
{
position: absolute;
}
#svgborder
{
border:5px solid black;
z-index: 0;
margin-left:auto;
border-radius: 5px;
display: inline-block;
}
#buttoninkr
{
z-index: 1;
}
添加了带有z-indexes的CSS代码。为什么我不使用svg按钮而不是jquery图像按钮是有原因的。
好的,就像您在plus.png http://jsfiddle.net/3wcq9aad/1/前面看到#svgmain
有任何想法吗?
解决了
#svgborders
{
position: absolute;
background-color: #535364;
border:5px solid black;
z-index: 0;
margin-left:auto;
border-radius: 5px;
display: inline-block;
}
#buttoninrk, #buttondekr, #home_btn
{
position: inherit;
top:0;
margin:10px;
z-index: 1;
}
#buttoninrk
{
right:0px;
}
#buttondekr
{
right:60px
}
编辑:造成差异的不是div的位置,而是简单地添加宽度和高度。因此,只要svgborder
在CSS中添加宽度和高度,原始HTML就可以正常工作:
http://jsfiddle.net/3wcq9aad/4/
(请注意,有时元素在文档中的位置可能会影响z-index的工作方式。)
如果将svgborder
div放在svg之前,则z-index可以工作,但是您需要知道SVG的宽度和高度,并将其设置在svgborder
div上。
<body>
<div class="comm_cont">
<div id="svgborder"></div>
<svg id='svgmain'></svg>
</div>
</body>
#svgborder
{
z-index: 2;
width:330px;
height:150px;
...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句