You can do it easily. These steps must be performed:
1) Have 3 blocks, such as DIV or UL LI, and add a hidden container inside (or it doesn't matter if you set the position using jQuery. If your structure is:
<div class="block"> <div class="invisible"></div> <div class="visible"></div> </div>
2) Attach the mouseenter and mouseleave events to all 3 blocks, for example:
$('.block').mouseenter(function() { // some code to show the hidden container $(this).find('.visible').show().addClass('visible_container'); }); $('.block').mouseleave(function() { // some other code to hide the shown container $('.visible_container').hide(); // Hide all the instances of .visible_container });
3) . You should change the JS or CSS according to the position methods for your elements, so when show()
is called, the element will be displayed directly above the element. For example, if a hidden block has a CSS position: absolute
rule, you should use:
$(this).find('.visible') .show() .addClass('visible_container') .css('top', $(this).offset().top+'px') .css('left', $(this).offset().left+'px');
In this case, the container shown will be set to the upper right corner of the hanging block.
Since the hidden container is a child of the block container, the mouseleave event will not be raised, so it will display well.
source share