问题
I have a svg
which contains two groups.
<svg viewBox="0 0 150 150" xmlns="http://www.w3.org/2000/svg">
<g id="gr1" fill="white" stroke="green" stroke-width="5">
<circle cx="40" cy="40" r="25" />
<circle cx="60" cy="60" r="25" />
</g>
<g id="gr2" fill="white" stroke="green" stroke-width="5">
<circle cx="90" cy="60" r="25" />
<circle cx="96" cy="40" r="25" />
</g>
</svg>
Is there a way, using C# or javascript (preferably C#), to hide the group gr2 at some event (button click, x value>y value, etc)? I know that visibility="hidden"
does what I want, but I don't know how to call it for a group of my SVG.
回答1:
Try this:
<svg viewBox="0 0 150 150" xmlns="http://www.w3.org/2000/svg">
<g id="gr1" fill="white" stroke="green" stroke-width="5">
<circle cx="40" cy="40" r="25" />
<circle cx="60" cy="60" r="25" />
</g>
<g runat="server" id="gr2" fill="white" stroke="green" stroke-width="5">
<circle cx="90" cy="60" r="25" />
<circle cx="96" cy="40" r="25" />
</g>
</svg>
and in c#
{
gr2.Visible = false;
}
来源:https://stackoverflow.com/questions/59262595/hide-svg-element-from-c-sharp