div背景缓和悬停覆盖

时间:2015-06-25 21:57:54

标签: javascript jquery html css css3

我的页面上设置了一个div,当用户将鼠标悬停在div上时,该div会显示一个叠加层。在其他网站上,例如在这里:http://www.elpassion.com有一个非常好的效果,也简化了div背后的背景。我似乎无法像我所看到的那样有效地工作,并且正在寻求一些支持和指导。

https://jsfiddle.net/Lopcnsuq/

HTML

<div class="portfolio-project">
<div class="portfolio-project-image">
<ul class="portfolio-project-image">
    <li>
        <div class="portfolio-project-image-one"></div>
        <a href="images/flyer_mock_up.jpg" class="html5lightbox" data-width="853" data-height="480" title="">
    <div class="portfolio-overlay">
        <div class="bt4">Marks & Spencer</div>
        <div class="bt5">Summer Fete A5 Flyers</div>
    </div>
</a>
    </li>
</ul>
</div>
</div>

CSS

.portfolio-project {
    width: 32%;
    height: 373px;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);
    margin-left:15px;
    float:left;
}


.portfolio-project-image{
    width: 100%;
    height: 373px;
}

.portfolio-project-image-one{
    width: 100%;
    height: 373px;
    background-image:url(../images/flyer_mock_up.jpg);
    background-position:center;

}



.portfolio-project-image-one:hover{
    width: 100%;
    height: 373px;
    background-image:url(../images/flyer_mock_up.jpg);
    background-position:center;
    display:block;

}

.portfolio-overlay {
  width:100%;
  height:100%;
  opacity: 0.75;
  position:absolute;
  background-color:black;
  transition: top 0.3s ease-in-out;
  display:block;
  -webkit-transition: top 0.3s ease-in-out;
            transition: top 0.3s ease-in-out;

}
.portfolio-overlay div {
    position:relative;
  display:inline-block;;

}

ul.portfolio-project-image { 
    list-style: none; 
    width:100% 

}

ul.portfolio-project-image li {
    position: relative;
    display: inline-block;
    width:100%;
  height: 100%;
  overflow: hidden;
  transition: 2s;
    -moz-transition: 2s;
    -webkit-transition: 2s;
    }


li:hover .portfolio-overlay {
  top: 0;
  display:block;
   transition: 2s;
    -moz-transition: 2s;
    -webkit-transition: 2s;}


.bt4 {
    text-align: center;
    margin-top: 160px;
    font: 200 12px/1.3 'Roboto', 'Helvetica Neue', 'Segoe UI Light', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color:#FFF;
    width:100%;
    height:10px;
    margin-left:auto;
    margin-right:auto;
}
.bt5 {
    text-align: center;
    font: 100 14px/1.3 'Roboto', 'Helvetica Neue', 'Segoe UI Light', sans-serif;
    font-size: 16px;
    font-weight: 200;
    color:#FFF;
    width:100%;
    height:10px;
    margin-left:auto;
    margin-right:auto;
    margin-top: 10px;
}

.bt5 a {
    text-align: center;
    font: 100 14px/1.3 'Roboto', 'Helvetica Neue', 'Segoe UI Light', sans-serif;
    font-size: 16px;
    font-weight: 200;
    color:#FFF;
    width:100%;
    height:10px;
    margin-left:auto;
    margin-right:auto;
    margin-top: 10px;
    text-decoration:none;
}

.bt6 {
    text-align: center;
    font: 200 12px/1.3 'Roboto', 'Helvetica Neue', 'Segoe UI Light', sans-serif;
    font-size: 30px;
    font-weight: 200;
    color:#FFF;
    width:100%;
    height:10px;
    margin-left:auto;
    margin-right:auto;
    margin-top: 30px;
}

1 个答案:

答案 0 :(得分:0)

我稍微改变了你的小提琴,以便当你悬停图像时你的背景图像会略微缩放,如elpassion-example中所示。

您可以使用以下css缩放/拉伸div的背景图像:

.portfolio-project-image:hover {
    background-size: 102% 102%;
    background-repeat: no-repeat;
    background-position: center center;
}

您可以通过以下链接找到示例背景图片的更新小提琴:https://jsfiddle.net/Lopcnsuq/9/