Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

<div id="floatbar">
    <a href="" onclick="make it float 10px under this yay">
</div>
like image 443
Steven Hammons Avatar asked Mar 11 '11 09:03

Steven Hammons


People also ask

How to show popup on mouseover using jQuery?

$(function() { $('a. popper'). hover(function() { $('#pop'). toggle(); }); });

How can get hover effect in jQuery?

jQuery hover() MethodThe hover() method specifies two functions to run when the mouse pointer hovers over the selected elements. This method triggers both the mouseenter and mouseleave events. Note: If only one function is specified, it will be run for both the mouseenter and mouseleave events.


2 Answers

the jquery

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

the css

#floatbar {
    position:relative;
}

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

the html

<a id="floatbar" href="#">
    <div class="popup">Hi there</div>
    click here
</a>
like image 141
Ed Fryed Avatar answered Sep 30 '22 06:09

Ed Fryed


Pure css solution:

<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/

like image 37
Stephan Muller Avatar answered Sep 30 '22 05:09

Stephan Muller