首页 > 解决方案 > 如何使用 svg.js 添加链接或用标签包裹圆圈

问题描述

我正在使用 svg.js 创建内部带有文本并居中的圆圈 我能够做到这一点

let draw = SVG('main');

// this is for the text
draw.plain(ele.ticket_id).attr({
            x: posX,
            y: posY,
            fill: '#fff',
            'alignment-baseline': 'central',
            'text-anchor': 'middle'
          })
              .font({
                size: Number((radius/2) * .5).toFixed(2)
              });
 // and this creates the circle
 circle.animate(500, 'quadIn').attr({
            fill: '#f06',
            id: element.ticket_id,
            class: element.status,
            cx: posX,
            cy: posY
          });

但我不确定如何用 a 标签包裹圆圈或文本,所以它应该是可点击的。我在 svg.js 文档中没有看到任何示例。

标签: svgsvg.js

解决方案


好的,它只是向元素添加一个 linkTo(url-here)


推荐阅读