【发布时间】:2023-03-27 13:43:01
【问题描述】:
使用 snapsvg.io,我想知道是否可以向 SVG 文本、圆圈或线条添加可点击的链接,例如 <a href="somelink.com"/>My Link</a> 标签。
我这里有一个例子是文本:
var s = Snap("#svg");
var text = s.text(x + 10, y - 5, 'My Text');
text.attr({
fill: doesExist ? alert : textColorOK,
fontSize: '10px',
'font-weight': '600',
'font-family': 'Arial Narrow, sans-serif',
'text-anchor': 'start',
cursor: doesExist ? 'pointer' : 'default'
});
我想用 snapsvg.io 来做这件事。此外,我想在纯 JavaScript 中执行此操作,而不是 jQuery。
【问题讨论】:
-
给它一个
id并使用$(id).click(function(){ window.location = "yourURL"})
标签: javascript svg snap.svg