2011-03-11 42 views
7

如何將彈出窗口懸停在jquery中的鏈接上?如何使彈出div懸停在jquery中的鏈接上?

<div id="floatbar"> 
    <a href="" onclick="make it float 10px under this yay"> 
</div> 
+0

你能至少提供的應該是什麼樣子的繪圖/截圖?這是不夠的信息工作。 – 2011-03-11 09:10:18

+0

請更具體。你是指工具提示嗎? – daryl 2011-03-11 09:24:18

回答

12

jQuery的

$("#floatbar").click(function(e){ 
    e.preventDefault(); 
    $(this).find(".popup").fadeIn("slow"); 
}); 

的CSS

#floatbar { 
    position:relative; 
} 

.popup { 
    position:absolute; 
    top:10px; 
    left:0px; 
    height:30px; 
    background:#ccc; 
    display:none; 
} 

的HTML

<a id="floatbar" href="#"> 
    <div class="popup">Hi there</div> 
    click here 
</a> 
+1

+1保持簡潔和簡單:) – SubniC 2011-03-11 09:27:18

+0

它似乎並沒有在這裏工作:http://jsfiddle.net/76S6F/ – 2013-05-18 14:56:20

+0

嘿安德森,它的工作只是沒有點擊,因爲沒有文字鏈接。看到我上面的編輯。或者只是訪問你的jsfiddle演示,並在彈出的div下面的標籤中放置單詞'click here'。 – 2013-05-29 09:11:04

1

也許它,當你使用類似Fancybox的jQuery或其他替代燈箱更容易?

10

純CSS解決方案:

<div id="floatbar"> 
    <a href="" onclick="make it float 10px under this yay">Link</a> 
    <div class="box">Popup box</div> 
</div> 

.box { 
    display:none; 
    position: absolute; 
    top: 30px; 
    left: 10px; 
    background: orange; 
    padding: 5px; 
    border: 1px solid black; 
} 

a:hover + .box { 
    display:block; 
} 

您只需在鏈接下面添加一個<div class="box">(popup text)</div>,它就可以用於每個有這種盒子的鏈接。

http://jsfiddle.net/mcdqt/

+0

在mouseLeave **。box ** div處隱藏。所以我不能將鼠標放在顯示的.box div上。顯示時如何將.box div懸停? – partho 2016-09-15 10:58:53