【问题标题】:CSS / Jquery - Responsive HoverCSS / Jquery - 响应悬停
【发布时间】:2014-08-04 00:05:44
【问题描述】:

我想为响应式博客列表实现悬停效果 -

基本上我正在使用这个的样式版本 - http://startbootstrap.com/3-col-portfolio 并且我想在将鼠标悬停在特定博客上时使用“readmore”按钮淡入灰色叠加层,就像在 ythis 快速模拟图像中一样 -

我想我可以在博客 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 填充所需的空间 - 或者这是否是实现我想要的最佳方式。有什么建议吗?

【问题讨论】:

  • 你还没有打开脚本元素:&lt;script type="text/javascript"&gt;
  • 你能做个小提琴吗?
  • 我尝试过使用给定的代码,但是当您将鼠标悬停在提供的图像上时,它会导致几乎无限的淡入淡出循环......
  • 嗨,克里斯,这不是完整的代码 - 只是一个片段来解释我在说什么 - 我会做一个小提琴
  • 不过,您可以使用 CSS 和 :hover 完成所有工作。

标签: jquery css responsive-design


【解决方案1】:

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

我忽略了你的代码并用不同的方式制作它!当你可以用css实现它时,不需要使用JQuery

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 " */
}

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

【讨论】:

    【解决方案2】:

    使用您的代码,我认为您可以尝试这样的事情......

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-12-03
      • 2010-12-11
      • 2013-08-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多