gpt4 book ai didi

javascript - 如何将图像放在 svg 标签前面

转载 作者:行者123 更新时间:2023-11-28 08:01:55 32 4
gpt4 key购买 nike

我正在使用 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com