[英]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.