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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5270921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:51:50  来源:igfitidea点击:

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

jqueryhtmlcsstooltip

提问by Steven Hammons

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>

回答by Ed Fryed

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>

回答by Stephan Muller

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.

您所要做的就是<div class="box">(popup text)</div>在链接下方添加一个,它将适用于每个具有此类框的链接。

http://jsfiddle.net/mcdqt/

http://jsfiddle.net/mcdqt/

回答by René H?hle

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

当您使用Fancyboxfor jQuery 或其他 Lightbox 替代品时,也许会更容易?