繁体   English   中英

如何将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
    });
});

我使用#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的位置,而只是增加了宽度和高度。 因此,只要您在CSS中为svgborder添加宽度和高度,原始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;
    ...
}

小提琴: http : //jsfiddle.net/3wcq9aad/3/

svg不支持z-index使用元素位置代替:$('element')。css('position','absolute');

jQuery中是否可以将div放在前面?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM