简体   繁体   English

带有悬停图像的可滚动div(溢出:隐藏)

[英]Scrollable div (overflow:hidden) with hover images

I have a div with overflow:auto and a table inside. 我有一个div具有overflow:auto和一个表。 The div creates a vertical scroll bar as desired. div根据需要创建一个垂直滚动条。 However, I want to have a preview hover state for each row. 但是,我希望每行都有一个预览悬停状态。 This means that this hover state Div would have to go beyond the boundaries of the containing div. 这意味着该悬停状态Div必须超出包含div的边界。 How would i do this with the overflow already set to hide my contents... z-index wont let me escape the parent. 我将如何使用已设置为隐藏我的内容的溢出来执行此操作... z-index不会让我脱离父级。

Since it is a vertical scrollbar, then you can set to overflow-y:scroll and not set the overflow horizontally. 由于它是垂直滚动条,因此可以将其设置为overflow-y:scroll,而不必将其水平设置。 Then just make sure your images only leaves the horizontal boundaries (not the verticals). 然后只需确保您的图像仅离开水平边界(而不是垂直边界)即可。

Next time, create a fiddle: http://jsfiddle.net/ and we can help you even faster :) 下次,创建一个小提琴: http : //jsfiddle.net/ ,我们可以帮助您更快:)

Use position:absolute; 使用position:absolute; and set the z-index to a visible value for the div that you wish to overflow its container. 并将您要溢出其容器的div的z-index设置为可见值。

i recently resolved a similar issue, this should help you out: 我最近解决了类似的问题,这应该可以帮助您:

https://stackoverflow.com/a/13383906/1063287 https://stackoverflow.com/a/13383906/1063287

also see related jsfiddle here: 也可以在这里查看相关的jsfiddle:

http://jsfiddle.net/rwone/eeaAr/ http://jsfiddle.net/rwone/eeaAr/

html html

<div id="wrapper">
<div id ="hbar_one"></div>
<div id="hbar_two"></div>
<div id="container_a">
<div id="container_b">
<div class="class1 class2 magic" data-unique-content=".hidden_db_data_div">
<img src="http://lorempixel.com/g/50/50/">
<div class="hidden_db_data_div">
some amazing html
</div>
</div>
<div class="class1 class2 magic" data-unique-content=".hidden_db_data_div">
<img src="http://lorempixel.com/g/50/50/">
<div class="hidden_db_data_div">
more amazing html
</div>
</div>
<div class="class1 class2 magic" data-unique-content=".hidden_db_data_div">
<img src="http://lorempixel.com/g/50/50/">
<div class="hidden_db_data_div">
even more amazing html
</div>
</div>
</div>
</div>
<div id="hbar_three"></div>
<div id="hbar_four"></div>
</div>

css 的CSS

#wrapper {
width: 300px;   
}
#hbar_one {
background: #cc0000;   
height: 50px;
}

#hbar_two {
background: #ffcc00;   
height: 50px;
}

#container_b {
height: 100px;
overflow-y: auto;
}

.hidden_db_data_div {
display: none;
background: #00AFF0;
width: 120px;
height: 150px;
color: red;
position:absolute;
overflow: hidden; 
z-index: 999;  
}

img {
width: 50px;
height: 50px;
}

.magic {
display: inline;
}

#container_a { position:relative; }

#hbar_three {
background: #cccccc;   
height: 50px;
}

#hbar_four {
background: #000000;   
height: 50px;
}

script 脚本

$(".magic").hover(
function () {
$(this)
.find('.hidden_db_data_div')
.css({'left':$(this).position().left+20 + "px", 'top':'-20px'})
.fadeIn(200);
},
function() { 
$(this)
.find('.hidden_db_data_div')
.fadeOut(100);
}                
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM