问题
How to create dynamic positioned hover popup, that can change direction from left to right depending on parent indent without tooltip plugins
HTML
<div class="main">
<div class="visible">visible content</div>
<div class="hidden">hidden content</div>
</div>
JS
$('.main > .visible').hover(function () {
$('.hidden').show();
},
function () {
$('.hidden').hide();
});
example (when hover over poster popup change the direction) http://www.ivi.ru/videos/all/all/all/by_new/?year_from=2010&year_to=2012
回答1:
You don't need jQuery to do this, you can do this in CSS.
Set .main to relative
and .visible/.hidden to absolute
so you can position .hidden "outside" .main, then have it displayed when you hover over .main.
jsfiddle example: http://jsfiddle.net/ZjZSk/1/
.main {
width:100px;
height:100px;
position:relative;
background:#ff0000;
}
.main:hover .hidden {
display:block;
}
.visible {
position:absolute;
top:0;
left:0;
width:100px;
height:100px;
}
.hidden {
position:absolute;
top:0;
left:100px;
width:100px;
height:100px;
display:none;
background:#aaaaff;
}
来源:https://stackoverflow.com/questions/10092658/dynamic-positioned-hover-popup