简体   繁体   English

我想把一个滚动条放到我的svg图像上,这样它就只占用我网页上的特定区域

[英]I want to put a scrollbar to my svg image so that it occupies only specific area on my webpage

I have a svg file which occupies almost the entire HTML Page. 我有一个svg文件,几乎占据整个HTML页面。 Instead i wish to put a scrollbar and give it only a specific space so that I can place other elements in the page. 相反,我希望放置一个滚动条,只给它一个特定的空间,以便我可以在页面中放置其他元素。 But it cuts off my image maybe because it has elements which have co-ordinates that don't fit inside the give space and the scrollbar also doesn't show up. 但它切断了我的图像可能是因为它的元素具有不适合放置空间的坐标,并且滚动条也没有显示出来。

How to get ScrollBars in SVG? 如何在SVG中获取ScrollBars? Add scrollbar to svg container 将滚动条添加到svg容器

Option 1 that I tried : 我试过的选项1:

    <svg viewbox = "0 0 825 1275" xmlns="http://www.w3.org/2000/svg" style="overflow-x: scroll; overflow-y: scroll;">
      <line stroke ="black" x1 = "787.5" y1 = "412.5" x2 = "712.5" y2 = "37.5" nodeIndex="1"></line><text text-anchor = "middle" dominant-baseline = "central" x = "758" y = "217" >a6</text><line stroke ="black" x1 = "787.5" y1 = "412.5" x2 = "712.5" y2 = "787.5" nodeIndex="1"></line>
...
...
...

Option 2 that I tried : 我试过的选项2:

    <div class="container">
    <Object type="image/svg+xml" id="mySVG"  data="svg/glycan-114.svg">
     Your browser does not support SVG
     </Object>
    </div>

CSS: CSS:

#container{
        height: 400px;
        width: 400px;
        overflow: scroll;
}
#mySVG {
    width :100px;
    height:1000px;
    position: relative;
    overflow: scroll;
}

Try wrapping the <svg></svg> in a <div> and applying an overflow scrollbar on the <div> : 尝试包裹<svg></svg><div>和应用上的溢流滚动条<div>

<div class="container">
    <svg>
        <line></line>
        <text></text>
        <line></line>
    </svg>
</div>

.container {
    width: 200px;
    height: 200px;
    overflow: scroll;
}

Any portion of the <svg> that doesn't fit within the container area can be accessed using the scrollbar. 可以使用滚动条访问<svg>中不适合容器区域的任何部分。

If you also require the <svg> to fully contain within the container area, you might want to play around with SVG transformations like scaling down the SVG. 如果您还要求<svg>完全包含在容器区域内,您可能希望使用SVG转换,例如缩小SVG。

Please refer to the following jsfiddle example. 请参考以下jsfiddle示例。

暂无
暂无

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

相关问题 我想限制我的文本框 numirec 和 1-10 - i want to put a limit on my textbox numirec and 1-10 only 我想将图像放入 <div> 代替图像数组 - I want to put my images in a <div> instead of an image array 如何将我的地图居中放置在容器上并调整大小以使其占据整个容器? - How can I center my maps on the container and adjust the size so that it occupies the entire container? 我已将此数据读入控制台。 我想在我的网页中显示“ exampleHeader”和“ exampleBody”。 我该怎么办? - I have this data reading into my Console. I want to display the “exampleHeader” and “exampleBody” in my webpage. How would I do so? 我想在我的网页上显示led开/关 - I want to show led on / off on my webpage 我想修改我的JavaScript,以便可以将每个轮播放在要显示的项目数上 - I want to modify my javascript so that I can put each carousel on how many items to be shown 如何禁用默认键盘? 我只想在我的网页上显示自定义键盘 - how to disable default keyboard? i want only the custom keyboard to be displayed in my webpage 我的函数在页面加载时正在运行,但是我只希望它在选定区域时运行 - My function is running when page loads, but I only want it to run when a selected area is picked 我想将 localStorage 添加到我的 angularJS 以便它会保存我在刷新浏览器后选择的图像 - I want to add localStorage to my angularJS so it will save the image that I chose after refeshing the browser JavaScript-我希望延迟一下按钮,因此每15秒只能单击一次 - JavaScript - I want to but a delay on my button so it can only be clicked once every 15 Seconds
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM