我有一个SVG元素,里面有很多元素.SVG元素有一个视图框,因此您可以按一个缩放按钮,元素看起来更大或更小.效果很好.现在的问题是,当元素溢出父SVG元素时,不会出现ScrollBars.
例:
<div width="100%" height="100%">
<svg height="100%" width="100%" style="overflow-x: auto; overflow-y: auto; "viewBox="0 0 793 1122">
<g>
...
<line y2="44.9792mm" y1="44.9792mm" x1="197.203mm" x2="12.7028mm"></line>
<line y2="44.9792mm" y1="44.9792mm" x1="197.203mm" x2="12.7028mm"></line>
<text x="43.4516mm" y="52.9167mm" style="font-size: 11pt;">S</text>
<rect x="0" width="210mm" y="0" height="297mm"></rect>
...
</g>
</svg>
</div>
Run Code Online (Sandbox Code Playgroud)
//here I set the viewbox after clicking the zoomOut-Button
float width = svg.getViewBox().getBaseVal().getWidth();
float height = svg.getViewBox().getBaseVal().getHeight();
svg.getViewBox().getBaseVal().setHeight((float) (height / 0.9));
svg.getViewBox().getBaseVal().setWidth((float) (width / 0.9));
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?我把溢出attribut放在svg和div标签中.不起作用.