2013-04-22 54 views
0

我試圖讓一個div顯示懸停區域的alt文本 - 相對於懸停區域進行定位。懸停區域顯示alt文本在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(); 
     }); 

    }); 
} 
}); 
+0

你在用傳單嗎? – 2013-04-22 05:58:53

回答

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 draggabele,那麼只有將dynamicallly改變位置

+0

嗯,我不希望div可拖動,並且我嘗試過使用css來定位它相對於懸停區域,但它似乎沒有區別? http://jsfiddle.net/pSbYX/ – user2306046 2013-04-25 03:21:31

+0

@ user2306046,我已經更新了答案,它會很好地工作。如果有效,請接受它作爲答案。 – 2013-04-25 06:07:24

+0

謝謝,這很棒。但看看我在頁面上添加其他內容時如何進一步向下移動框?我該如何調整? (我加了h1)http://jsfiddle.net/pSbYX/2/ – user2306046 2013-04-29 04:54:01