如何让一个弹出式div悬停在jquery中的一个链接上?

时间:2021-01-29 01:27:43

How to make a popup hover over a link in jquery?

如何使弹出窗口悬停在jquery中的链接上?

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

3 个解决方案

#1


12  

the jquery

jquery

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

the css

css

#floatbar {
    position:relative;
}

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

the html

HTML

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

#2


11  

Pure css solution:

纯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;   
}

All you have to do is add a <div class="box">(popup text)</div> below the link and it'll work for every link that has such a box.

您所要做的就是在链接下方添加一个

(弹出文本) ,它将适用于具有此类框的每个链接。

http://jsfiddle.net/mcdqt/

http://jsfiddle.net/mcdqt/

#3


1  

Perhaps its easier when you use something like Fancybox for jQuery or another Lightbox alternative?

当您使用Fancybox等jQuery或其他Lightbox替代品时,它可能更容易吗?

#1


12  

the jquery

jquery

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

the css

css

#floatbar {
    position:relative;
}

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

the html

HTML

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

#2


11  

Pure css solution:

纯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;   
}

All you have to do is add a <div class="box">(popup text)</div> below the link and it'll work for every link that has such a box.

您所要做的就是在链接下方添加一个

(弹出文本) ,它将适用于具有此类框的每个链接。

http://jsfiddle.net/mcdqt/

http://jsfiddle.net/mcdqt/

#3


1  

Perhaps its easier when you use something like Fancybox for jQuery or another Lightbox alternative?

当您使用Fancybox等jQuery或其他Lightbox替代品时,它可能更容易吗?