javascript - 将“圆圈”添加到可点击的 javascript 函数中
问题描述
我有 js 允许受访者点击特定的形状/图像并使其可点击。目前我将其设置为允许矩形和多边形,但我想将“圆形”添加为形状,但我不确定如何执行此操作。我的代码在这里。“圆圈”代码不起作用。我试图重用 poly 脚本,但没有运气。这有点新,所以任何帮助将不胜感激!
function addClickable(shape, coords) {
area.push('<area class="area" href="#0" shape="' + shape + '" coords="' + coords.join(",") + '" style="outline: none;" title="" />');
if (shape.toLowerCase() == "rect") {
highlight.push('<rect x="' + coords[0] + '" y="' + coords[1] + '" width="' + (coords[2] - coords[0]) + '" height="' + (coords[3] - coords[1]) + '" style="fill-opacity:0.7; fill: none;" class="highlight" />');
}
if (shape.toLowerCase() == "poly") {
var newCoords = coords.join(" ").replace(/(\d+)\s(\d+)\s/g, '$1, $2 ');
highlight.push('<polygon points="' + newCoords + '" style="opacity: 0.7; fill: none;" class="highlight" />');
}
if (shape.toLowerCase() == "circle") {
var newCoords = coords.join(" ").replace(/(\d+)\s(\d+)\s/g, '$1, $2 ');
highlight.push('<circle points="' + newCoords + '" style="opacity: 0.7; fill: none;" class="highlight" />');
}
}
解决方案
推荐阅读
- cmake - Windows上的clion cmake二进制输出目录问题
- python - 了解已知错误的修复:cx_Freeze & Python 3.7
- java - getPersistedString 具有受保护的访问权限
- python - 将日期时间打印为 pytz.timezone("Etc/GMT-5") 会产生不正确的结果
- sql - SQL Server 中的 IF Exists (Query) vs IF(ResultCount > 0) 哪个查询执行得更好
- php - GRAV git-sync 插件更新崩溃网站,有人遇到/解决了吗?
- javascript - JWT 令牌未定义
- python - 无法在 tkinter 中将按钮状态更改为“禁用”
- sql - 使用表 1 从表 2 中检索值
- angular - 我如何将 .svg 图像用于本机脚本闪屏、背景和所有图标、按钮?