CSS / Jquery - 响应式悬停

时间:2014-06-13 12:20:58

标签: jquery css responsive-design

我想对响应式博客列表实施悬停效果 -

基本上我使用的是这个版本的样式 - http://startbootstrap.com/3-col-portfolio,而且我喜欢用“阅读更多”来淡入灰色叠加层。按钮,只要悬停在特定的博客上,就像在快速模拟的图像中那样 -

enter image description here

我想我可以在博客div中将div放在另一个上面并在悬停时淡入/淡出 -

<div class="col-md-4 portfolio-item">
        <div style="background:#FFF;" class="top">
            <a href="#project-link">
                <img class="img-responsive" src="http://breadwinningmama.com/wp-content/uploads/2013/04/fitness-running-shoes_fe.jpg">
            </a>
            <h3><a href="#project-link">A Fitness Article</a>
            </h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna.. <a href="articleInfo.html">Read More</a></p>
        </div>
        <div style="background:#000; width:100px; height:100px;" class="cover">
        read more
        </div>

        <div>

        </div>
        </div>


$(document).ready(function() {

$('.portfolio-item ').mouseenter(function() {
  $('.top').fadeOut('slow', function() {
    // Animation complete.
  });

  $('.cover').fadeIn('slow', function() {
    // Animation complete.
  });
}).mouseleave(function() {
  $('.top').fadeIn('slow', function() {
    // Animation complete.
  });

  $('.cover').fadeOut('slow', function() {
    // Animation complete.
  });
 });
 });
</script>

但是由于它的反应,我不确定如何让每个div填充所需的空间 - 或者这是否是实现我想要的最佳方式。有什么建议吗?

2 个答案:

答案 0 :(得分:1)

如果您正在寻找图片所具有的效果,那么您可能正在寻找: JSFiddle

我忽略了您的代码并以不同的方式制作了代码!当您可以使用JQuery

来实现时,无需使用css

<强> HTML:

<a href="#" class="wrapper">
    <span class="text">
        Read More!
    </span>
    <img src="http://www.1stwebdesigner.com/wp-content/uploads/2009/11/webdesign-books-wishlist/css-missing-manual-books-web-development-books.jpg">
</a>

<强> CSS:

.wrapper {
    position: relative;
    padding: 0;
    width:100px;
    display:block;
}
.text {
    position: absolute;
    top: 0;
    color:#f00;
    background-color:rgba(255,255,255,0.7);
    width: 300px;
    height: 391px;
    line-height:100px;
    text-align: center;
    z-index: 10;
    opacity: 0;
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
}
.text:hover {
    opacity:1;
}

img {
    z-index:1;
}
span.text
{
  width: 300px;
  height: 391px;
  color: #000;
  text-align: center;
  line-height: 391px; /* Magic Trick to align text " vertically " */
}

如果这对您有用,请告诉我! :)

答案 1 :(得分:1)

使用你的代码,我想你可以试试这样的东西......

HTML

<div class="col-md-4 portfolio-item">
    <div class="top">
        <a href="#project-link">
            <img class="img-responsive" src="http://breadwinningmama.com/wp-content/uploads/2013/04/fitness-running-shoes_fe.jpg">
        </a>
     <h3><a href="#project-link">A Fitness Article</a></h3>
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam viverra euismod odio, gravida pellentesque urna...</p>
</div>
<div class="cover"><a href="articleInfo.html">Read More</a></div>

CSS

.portfolio-item{
    position:relative;
}

.cover{
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background:#444;
    opacity: .4;    
}

.portfolio-item:hover .cover{
    display:block;
}