javascript - 使用 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>
推荐阅读
- php - Wordpress / Learndash - 添加评论时发送电子邮件
- python - 语法错误:SELECT username FROM TAMS WHERE NAME IN caner?
- flutter - 如何在 Flutter 中保持专注于 TextField 但不显示键盘?
- php - Laravel 从 index.php 和 index.html 重定向到域
- python - 给定数字列表将返回 true 或 false 的列表理解
- javascript - 对象内数组的平均值
- python - python-dotenv 在自定义包中不起作用
- nginx - Nginx 将我的 localhost 端口请求路由到外部 url
- powershell - 转换 PowerShell 对象以在条件下使用它
- python-3.x - 带有 Python 3 的 MacOS 上的 Ansible 2.10