【问题标题】:jquery Tool tip for svg element path用于 svg 元素路径的 jquery 工具提示
【发布时间】:2013-09-05 15:43:44
【问题描述】:
<path xmlns="http://www.w3.org/2000/svg" d="M477.63,166.84l0.51,0.9l0.33,0.14l0.9,-0.21l1.91,0.47l3.68,0.16l0.17,-0.05l1.2,-0.75l2.78,-0.67l1.72,1.05l1.02,0.24l-0.97,0.97l-0.91,2.17l0.0,0.24l0.56,1.19l-1.58,-0.3l-0.16,0.01l-2.55,0.95l-0.2,0.28l-0.02,1.23l-1.92,0.24l-1.68,-0.99l-0.27,-0.02l-1.94,0.8l-1.52,-0.07l-0.15,-1.72l-0.12,-0.21l-0.99,-0.76l0.18,-0.18l0.02,-0.39l-0.17,-0.22l0.33,-0.75l0.91,-0.91l0.01,-0.42l-1.16,-1.25l-0.18,-0.89l0.24,-0.27Z" 
    data-code="BG" 
    fill="#cecdcd" 
    fill-opacity="1" 
    stroke="none" 
    stroke-width="0" 
    stroke-opacity="1" 
    fill-rule="evenodd" 
    id="test" 
    title="this as tool-tip" 
    class="jvectormap-region jvectormap-element"/>

我需要 title 属性值作为工具提示。我尝试了以下但没有任何反应。

$("path", svgRoot).mouseover(function() {
    //var content = $(this).attr("title");
    var id = $(this).attr("id");
    if (id != undefined) {
        $(this).tooltip();
    }
});

【问题讨论】:

  • 您是否包含任何工具提示插件?
  • 是的,我包括了 code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
  • 它是否正确检索id?已经有一段时间了,但我想我记得 jquery 无法获取attr 的 SVG 节点。编辑:抱歉,我刚刚查看了一些旧代码及其在 SVG 节点上不起作用的 addClassremoveClassattr 应该可以工作
  • id 没有问题我为 svg 创建了一个对象
  • @RoryMcCrossan 感谢您编辑我的代码

标签: jquery svg tooltip jquery-svg jquery-ui-tooltip


【解决方案1】:

在 SVG 中,工具提示不是由 title 属性表示的,您需要一个 &lt;title&gt; 子元素来代替。

即而 HTML 工具提示看起来像这样:

<p title="title">This is a paragraph.</p>

SVG 工具提示如下所示:

<text y="50"><title>This is the tooltip</title>This is some text<text>

或者在你的情况下

<path xmlns="http://www.w3.org/2000/svg" d="M477.63,166.84l0.51,0.9l0.33,0.14l0.9,-0.21l1.91,0.47l3.68,0.16l0.17,-0.05l1.2,-0.75l2.78,-0.67l1.72,1.05l1.02,0.24l-0.97,0.97l-0.91,2.17l0.0,0.24l0.56,1.19l-1.58,-0.3l-0.16,0.01l-2.55,0.95l-0.2,0.28l-0.02,1.23l-1.92,0.24l-1.68,-0.99l-0.27,-0.02l-1.94,0.8l-1.52,-0.07l-0.15,-1.72l-0.12,-0.21l-0.99,-0.76l0.18,-0.18l0.02,-0.39l-0.17,-0.22l0.33,-0.75l0.91,-0.91l0.01,-0.42l-1.16,-1.25l-0.18,-0.89l0.24,-0.27Z" 
    data-code="BG" 
    fill="#cecdcd" 
    fill-opacity="1" 
    stroke="none" 
    stroke-width="0" 
    stroke-opacity="1" 
    fill-rule="evenodd" 
    id="test" 
    class="jvectormap-region jvectormap-element">
    <title>this as tool-tip</title>
</path>

您不需要 jquery,它也不适用于 SVG 工具提示。

【讨论】:

    猜你喜欢
    • 2016-08-19
    • 2014-09-23
    • 2021-07-04
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多