javascript - "Circular"菜单使用 SVG

标签 javascript html css svg

<分区>

我想做一个圆形菜单,包含可变(未知)数量的元素,也就是说,我的链接将放置在一个圆圈上。

我想用SVG画圆圈,但是如何在圆圈上等距放置元素呢?

我可以从代码开始:

.container {border: 1px solid red; background: lightblue;}
<figure>
  <figcaption>Inline, auto size</figcaption>
  <div class="container">
    <svg viewBox="0 0 10 10"><use xlink:href="#my-circle"/></svg>
    <div>one</div>
    <div>two</div>
    <div>tree</div>
  </div>
</figure>
<svg>
  <symbol id="my-circle" >
    <g fill="transparent" stroke="darkgoldenrod" stroke-width="0.1">
      <circle r="3" transform="translate(5,5)" />
    </g>
  </symbol>
</svg>

圆应该随着容器大小的调整而调整,并且元素应该移动。

有没有不需要大量 JS 的方法?

最佳答案

您可以在圆形路径上使用文本:

svg{border:1px solid}
a:hover{fill:red; }
<svg viewBox="0 0 200 200">
<defs>
   <desc>The path used for the text</desc>
   <path id="c" d="M150,100 A50,50 0 1 1 150,99.99z"  />
</defs>

<use xlink:href="#c" stroke="#d9d9d9" fill="none"/>

     <text font-size="20" >
      <textPath xlink:href="#c" startOffset="50%">
            <a xlink:href="https://stackoverflow.com">stack</a>
      </textPath>
  </text>
  
  <text font-size="20" text-anchor="middle">
      <textPath xlink:href="#c" startOffset="75%">
            <a xlink:href="https://stackoverflow.com">over</a>
      </textPath>
  </text>
  
  <text font-size="20" text-anchor="end">
      <textPath xlink:href="#c" startOffset="100%">
            <a xlink:href="https://stackoverflow.com">flow</a>
      </textPath>
  </text>

</svg>

关于javascript - "Circular"菜单使用 SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53639068/

上一篇:javascript - 如何让这个链接在这个元素上工作?

下一篇:html - 根据本地 html 条件使用 [ngClass] 添加类

相关文章:

Javascript 语法错误意外标记(文件输入)

javascript - 如何切换侧边栏?

javascript - jQuery 设置子元素回调

html - 像电视屏幕一样在另一个 div 内部的 Div

javascript - 为什么 Mozilla FF 不更新 innerHTML?

html - 无法在 iOS 上的 Bootstrap 模式中滚动 iframe

javascript - 单击后将显示更改为 Ajax 微调器的 HTML 按钮

html - 从 node-webkit 访问 USB 设备?

css - 在 magento 中以 2 行显示更长的产品名称

javascript - html 源中缺少 "&lt;/style&gt;"