繁体   English   中英

图像地图与Bootstrap工具提示没有显示在正确的位置

[英]image Map with Bootstrap Tooltips not showing in correct spot

我有一个图像映射,当用户将鼠标悬停在该图像的特定部分上时,我想使用Bootstrap提供的内置工具提示。

我遇到的问题是工具提示没有显示在正确的位置。 现在它显示在图像的左上角,用于图像映射的所有区域。

如何在不必单独重新定位每个工具提示的情况下将工具提示移动到各自的区域下? 它应该自动在rec定义的范围内。

这是我正在使用的地图代码:

<img id="Image-Maps-Com-process-map" src="images/osh drawing.png" border="0" width="600" height="600" orgWidth="600" orgHeight="600" usemap="#process-map" alt="" />
<map name="process-map" id="ImageMapsCom-process-map">
<area  alt="" title="Wood Burning Stove" href="#" class="tooltip-bot" data-original-title="Title text here" shape="rect" coords="478,186,572,296" style="outline:none;" target="_self"     />
<area  alt="" title="Rough Cut Lumber" href="#" class="tooltip-bot" data-original-title="Title text here" shape="rect" coords="184,1,395,148" style="outline:none;" target="_self"     />
<area  alt="This is the description maybe" title="Distributing" href="#"class="tooltip-bot" data-original-title="Title text here" shape="rect" coords="45,398,304,577" style="outline:none;" target="_self"  />
<area  alt="" title="Shipping Materials" href="#"class="tooltip-bot" data-original-title="Title text here" shape="rect" coords="9,52,141,183" style="outline:none;" target="_self"     />
<area  alt="" title="Sawdust" href="#"class="tooltip-bot" data-original-title="Title text here" shape="rect" coords="302,311,410,385" style="outline:none;" target="_self"     />
<area  alt="" title="Electricity" href="#"class="tooltip-bot" data-original-title="Title text here" shape="rect" coords="430,0,570,113" style="outline:none;" target="_self"     />
<area  alt="manufacturing" title="Manufacturing" href="#"class="tooltip-bot" data-original-title="Title text here" shape="poly" coords="348,193,213,197,188,313,221,368,296,362,300,310,357,302,363,193" style="outline:none;" target="_self"     />
</map>

我不是专家,但我觉得这是因为area元素没有实际的高度或宽度。 它们的边界是使用coords属性建立的,这可能不是由bootstrap查看的。

可能有更好的方法来做到这一点,但一个简单的解决方法是将下面的代码添加到你的页面。这将把工具提示与指针本身保持固定的距离。

这是一个有效的jsFiddle

$(document).mousemove( function(e) {    
    var mouseX = e.pageX - $('#Image-Maps-Com-process-map').offset().left - 40;
    var mouseY = e.pageY - $('#Image-Maps-Com-process-map').offset().top + 20;
    $('.tooltip').css({'top':mouseY,'left':mouseX}).fadeIn('slow');
}); 

我知道这是一个相当陈旧且回答的问题,但我想我会把它扔进去,因为我遇到了同样的问题而在其他地方找不到确切的答案。 我有一个网站,它使用较旧的asp.net图表控件,在图表上绘制图像映射,以便显示工具提示。 要在其区域属性上使用工具提示并将它们放在正确的位置,我使用下面的代码。 请注意,我仍然必须使用抵消金额,但它运作得相当好。 “.maparea”是一个动态应用于所有地图区域属性的类。 我也使用鼠标悬停,因为我不需要工具提示不断移动。

$('.maparea').mouseover(function (e) {
    var position = $(this).attr('coords').split(',');
    x = +position[0];
    y = +position[1];
    $('.tooltip').css({ 'top': y + 60, 'left': x - 83 }).fadeIn('slow');
    $('.tooltip-arrow').css({ 'left': '50%' });
});

编辑:

我不得不放入工具提示箭头行,因为Google Chrome正在弄乱工具提示箭头的对齐方式。 不要认为这会在所有场景中发生,但由于我的页面有可折叠的菜单,这些菜单会自行调整页面大小,因此它们会将对齐关闭。

我的弹出窗口解决方案(基于鼠标点击位置):

var clickTop,clickLeft=0;
    $(document).click(function(e){
        clickTop =e.pageY;
        clickLeft =e.pageX;

    });
    $().ready(function(){
        var popovers=$('[data-toggle="popover"]');

        popovers.popover({
            placement: 'bottom center',
            html:true,
            trigger:'focus'
        }).on("shown.bs.popover", function(e){
            $('.popover').css({top:clickTop,left:clickLeft-100});
        })

    });

我已经采用了@Big EMPin解决方案(右侧工具提示),所以它最终适用于我:

<div style="position: relative;display: inline-block">
    <img style="max-width: 100%" src="../static/img/JavaPyramid.jpg" usemap="#courses">
</div>
<map name="courses">
    <area shape="rect" coords="120,10,200,85" href="/view/startjava" data-toggle="tooltip" data-placement="right" title="StartJava" class="maparea">
    <area shape="rect" coords="85,100,165,175" href="/view/basejava" data-toggle="tooltip" data-placement="right" title="BaseJava" class="maparea">
    <area shape="rect" coords="50,190,130,265" href="/view/topjava" data-toggle="tooltip" data-placement="right" title="TopJava" class="maparea">
    <area shape="rect" coords="20,280,100,355" href="/view/masterjava" data-toggle="tooltip" data-placement="right" title="MasterJava" class="maparea">
</map>
<script>
    $('.maparea').mousemove(function (e) {
      var pos = $(this).attr('coords').split(',');
      $('.tooltip').css({'left': parseInt(pos[2]) + 5, 'top': parseInt(pos[1]) + 35}).fadeIn('slow');
    });
</script>

解决方案可以在http://javaops.ru/看到

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM