如何将img放在svg标签的前面
How to put img in front of svg tag
我使用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到前面?
相关文章:
- 在<页眉>标签
- 如何在下面的ES6循环中获得前面的文本
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- iframe正在添加标签,需要删除它们
- 如何自动调整标签的高度以适应内容
- Jquery标签插件粘贴问题
- Twitter引导程序Typeahead-Id&标签
- 下拉列表在使用z索引放置在前面后停止工作
- Highcharts-如何在自定义格式化程序中获得默认的y轴标签格式化程序
- Morris.js折线图x轴标签在调整大小后消失
- JavaScript goto 标签如何使用内部循环
- 显示某个用户ID的某个标签的30张Instagram图片
- 标签客户端的设置值
- 谷歌图表显示所有标签
- 如何在图片和边缘之间居中设置标签
- jQuery在.each中查找前面的元素标签
- PHP逻辑到Javascript前面成html标签
- 如何将img放在svg标签的前面
- 在JavaScript中用前面的标签填充文本框
- 我正在锚标签的前面添加一个图标,但是,我想阻止它添加图标多次