我想知道是否有人可以帮助我。我想创建一个on click和hover效果,将div作为一种叠加层显示在另一个div上。我最好喜欢使用css3过渡,但如果我必须用jquery做,我会这样做。
我在网上发现了一些内容,例如http://jsfiddle.net/UezUj/1/但是这更像是幻灯片切换效果,而且它走错了路。我想创建类似http://www.ashtonsmith.co.uk/的内容(如果您将鼠标悬停在分发和后勤上),但标题会向上滑动以显示内容。
<div class="col-md-4 box__industries">
<div>
<div class="image fill">
<img src="http://lorempixel.com/g/400/200/" width="363" height="159">
</div>
<div class="content">
<h5>Title</h5>
This is my content
</div>
</div>
</div>
我希望div .content在点击和悬停时向上滑动图片。
提前感谢。
答案 0 :(得分:7)
请尝试以下代码:
.box_industries
{
background: green;
overflow: hidden;
text-align: center;
position: relative;
}
.box_industries .content
{
background: rgba( 0, 0, 0, 0.9 );
bottom: -100%;
color: #fff;
height: 100%;
left: 0%;
text-align: center;
position: absolute;
transition: bottom 0.5s ease;
width: 100%;
}
.box_industries:hover .content
{
bottom: 0%;
}
<div class="col-md-4 box_industries">
<div>
<div class="image fill">
<img src="http://lorempixel.com/g/400/200/" width="363" height="159">
</div>
<div class="content">
<h5>Title</h5>
This is my content
</div>
</div>
</div>
答案 1 :(得分:1)
.box-wrapper {
display: block;
position: relative;
z-index: 1;
width: 200px;
height: 200px;
background: url('http://lorempixel.com/200/200/') #808080 no-repeat center center;
overflow: hidden;
/*hidden the content inside*/
}
.box-content {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 200px;
/*make the content lies under wrapper*/
background: rgba(128, 128, 128, 0.8);
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
/*make the smooth transition in 0.3s*/
color: #fff;
}
.box-wrapper:hover .box-content {
top: 0;
/*bring the content back*/
}
<a class="box-wrapper" href="#">
<div class="box-content">
<h1>Content</h1>
</div>
</a>
答案 2 :(得分:1)
.box_industries
{
background: green;
overflow: hidden;
text-align: center;
position: relative;
}
.box_industries .content
{
background: rgba( 0, 0, 0, 0.9 );
bottom: -100%;
color: #fff;
height: 100%;
left: 0%;
text-align: center;
position: absolute;
transition: bottom 0.5s ease;
width: 100%;
}
.box_industries:hover .content
{
bottom: 0%;
height:10%;
}
<div class="col-md-4 box_industries">
<div>
<div class="image fill">
<img src="http://lorempixel.com/g/400/200/" width="363" height="159">
</div>
<div class="content">
<h5>Title</h5>
This is my content
</div>
</div>
</div>
答案 3 :(得分:0)
试试这个。虽然,在这一个文本低于图片,只有CSS,没有js。这是在codepen中。希望它有所帮助。
http://codepen.io/the-afshin/pen/mEBNjA
但无论如何这里是css:
.wrapper {
margin: 0;
padding: 0;
}
.image {
margin: 0;
padding: 0;
}
.content {
color: blue;
font-size: 35px;
padding: 0;
margin: 0;
}
.main {
border: 2px solid red;
display: inline-block;
}
.main:hover {
transform: translateY(-100px);
transition: transform 2s;
}
和html:
<div class="col-md-4 box__industries wrapper">
<div class="image fill">
<img src="http://lorempixel.com/g/400/200/" width="363" height="159">
</div>
<div class="main">
<h5 class="content">Title</h5>
<p class="content">This is my content</p>
</div>
</div>
</div>