Dynamic positioned hover popup

风格不统一 提交于 2019-12-12 04:59:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!