【问题标题】:Map with hover area showing alt text in div - relative to hovered area带有悬停区域的地图在 div 中显示 alt 文本 - 相对于悬停区域
【发布时间】:2013-04-14 22:27:18
【问题描述】:

我试图让一个 div 与悬停区域的替代文本一起显示 - 相对于悬停区域定位。

我可以显示文本,但位置不正确。

这是我的 js:

$(document).ready(function() {
if($('#Map')) {
    $('#Map area').each(function() {
    var altText = $(this).attr("alt");
        $(this).mouseover(function() {
    $("#popup").html(altText);
            $('#popup').show();

        });

        $(this).mouseout(function() {
    var altText = $(this).attr("alt");
            $('#popup').hide();
        });

    });
}
});

【问题讨论】:

  • 你在使用传单吗?

标签: javascript map hover area


【解决方案1】:

这样就可以了

<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function () {
    $("#popup").draggable();
    if ($('#Map')) {
        $('#Map area').each(function () {
            var altText = $(this).attr("alt");
            $(this).mouseover(function (event) {

                $("#popup").html(altText);
                $("#popup").css({ 'top': event.clientY, 'left': event.clientX });
                $('#popup').show();

            });

            $(this).mouseout(function () {
                var altText = $(this).attr("alt");
                $('#popup').hide();
            });

        });
    }
});

你需要让 div 拖动,然后它才会动态改变位置

【讨论】:

  • 嗯,我不希望 div 可拖动,我尝试使用 css 将其相对于悬停区域定位,但似乎没有什么区别?? jsfiddle.net/pSbYX
  • @user2306046,我已经更新了答案,它将完美运行。如果它有效,请接受它作为答案..
  • 谢谢,太好了。但是看看当我向页面添加任何其他内容时,它会如何将框进一步向下移动?我该如何调整? (我加了h1)jsfiddle.net/pSbYX/2
猜你喜欢
  • 2013-01-30
  • 2012-10-24
  • 2012-12-15
  • 1970-01-01
  • 1970-01-01
  • 2013-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多