我使用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
});
});
我尝试了z-index #svgborder和#buttoninkr,但是没有帮助我。如何把按钮在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-index的css代码。这是为什么我不使用svg按钮,而不是jquery图像按钮的原因。
好的,你可以看到#svgmain在plus.png 前面http://jsfiddle.net/3wcq9aad/1/
任何想法?
解决 #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
}
EDIT:造成差异的不是div的位置,而是简单地添加了宽度和高度。因此,只要在CSS中为svgborder
添加宽度和高度,原始HTML就可以正常工作:
(注意,有时候,元素在文档中的位置可以对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;
...
}
小提琴:http://jsfiddle.net/3wcq9aad/3/
svg不支持z-index使用元素位置代替:$("元素"). css("位置","绝对");
是否有一种方法在jQuery把一个div到前面?