【问题标题】:How to create a html tooltip on top of image map?如何在图像地图上创建 html 工具提示?
【发布时间】:2011-07-25 15:16:42
【问题描述】:

我有以下代码:

<div style="width:100%" align="center">
    <img   src="./platform-logos-big.png" alt="Icons of platforms we support: Windows Linux and MacOS X" border="0" align="middle" usemap="#Map">
    <map name="Map">
        <area shape="rect"  coords="0,0,87,100" href="#Linux" alt="Click here to download Linux version of CloudClient">
        <area shape="rect" coords="88,0,195,100" href="#Windows" alt="Click here to download Windows version of CloudClient">
        <area shape="rect" coords="196,0,300,100" href="#MacOsX" alt="Click here to    download MacOsX version of CloudClient">
    </map>
</div>
<div class="WTT">
tooltipWin
</div>
<div class="LTT">
tooltipLin
</div>
<div class="MTT">
tooltipMac
</div>

我想显示我的纯 html 工具提示出现在鼠标顶部并随之移动。如何用 jQuery 做这样的事情?

【问题讨论】:

    标签: javascript jquery html image map


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      确实,您应该为所有工具提示提供一个通用类,并为所有元素提供一个 id,但这对您现有的 HTML 无效。

      $('.WTT,.LTT,.MTT').css({
          position: 'absolute'
      }).hide()
      $('area').each(function(i) {
          $('area').eq(i).bind('mouseover', function(e) {
              $('.WTT,.LTT,.MTT').eq(i).css({
                  top: e.pageY,
                  left: e.pageX
              }).show()
          })
          $('area').eq(i).bind('mouseout', function() {
              $('.WTT,.LTT,.MTT').hide()
          })
      })
      

      在这里提琴:http://jsfiddle.net/billymoon/BmxR7/

      【讨论】:

      • 带有 win/lin/mac 标志看起来更好——不过 win 和 lin 是错误的 :) 就像偏移量和 mousemove 更新一样——尽管绑定时可以将其添加到 mouseover 事件.我在这里更新了一些小改动:jsfiddle.net/billymoon/X6P9M
      • 改进了@Rella jsfiddle.net/48qd5abu 原版在“绝对包装”页面(如主题)中不起作用
      【解决方案3】:

      在您的area 标签上粘贴title="your tooltip"。

      【讨论】:

      • 这将不允许任何 HTML 标记 -- 只是文字文本。
      【解决方案4】:

      关于使用jQuery UI for map > area > tooltip,需要添加:

      $("area").tooltip({ track: true });
      

      还有,样式:

      .ui-tooltip { }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多