作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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 索引,但它对我没有帮助。如何将按钮放在 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 索引的 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
}
最佳答案
编辑: 造成差异的并不是 div 的位置,而是简单地添加了宽度和高度。因此,只要在 CSS 中向 svgborder
添加宽度和高度,原始 HTML 就可以正常工作:
http://jsfiddle.net/3wcq9aad/4/
(请注意,有时,文档中元素的位置可能会影响 z-index 的工作方式。)
<小时/>如果将 svgborder
div 放在 svg 之前,则 z-index 将起作用,但您需要知道 SVG 的宽度和高度并将其设置在 svgborder 上
分区。
<body>
<div class="comm_cont">
<div id="svgborder"></div>
<svg id='svgmain'></svg>
</div>
</body>
#svgborder
{
z-index: 2;
width:330px;
height:150px;
...
}
fiddle :http://jsfiddle.net/3wcq9aad/3/
关于javascript - 如何将图像放在 svg 标签前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25276919/
我是一名优秀的程序员,十分优秀!