javascript - 当我裁剪照片时,它们最终将标题隐藏在缩略图中

标签 javascript jquery html twitter-bootstrap css

当我裁剪照片时,它们最终将标题隐藏在缩略图内。我该怎么做才能使字幕内容出现并使图像具有相同的高度。

我想实现这样的目标 ![][2]

$( document ).ready(function() {
    var heights = $(".thumnbnail").map(function() {
        return $(this).height();
    }).get(),

    maxHeight = Math.max.apply(null, heights);

    $(".thumnbnail").height(maxHeight);
});
.thumbnail {
 height: 200px;
 width: 300px;
 overflow: hidden;
}
.thumbnail img {
 height: auto;
 width: 600px;
}
<div class="row">
    <div class="col-md-3">
        <a href="#">
        <div class="thumbnail">
                <img src="http://ksassets.timeincuk.net/wp/uploads/sites/55/2017/11/GettyImages-873359588-920x584.jpg" alt="osooabina"  class="img-responsive image thumbnail">
                <div class="caption">
                  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.
                </div>                
        </div>
        </a>
    </div>    
    <div class="col-md-3">
        <a href="#">
            <div class="thumbnail">
                <img src="https://i.pinimg.com/736x/22/5e/80/225e80ea57b247c188ac160ed34fe3cf--ariana-grande-tattoos-ariana-grande-no-makeup.jpg" alt="" class="img-responsive">
                <div class="caption">
                  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.
                </div>
            </div>  
        </a>
    </div>    
    <div class="col-md-3">
        <a href="#">
            <div class="thumbnail">
                <img src="http://gazettereview.com/wp-content/uploads/2015/12/Eminem-Featured-image.jpg" alt="osooabina"  class="img-responsive image thumbnail">
                <div class="caption">
                  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.
                </div>
            </div>
        </a> 
    </div>  
    <div class="col-md-3">
        <a href="#">
            <div class="thumbnail">
                <img src="https://www.biography.com/.image/t_share/MTQ3MzM3MTcxNjA5NTkzNjQ3/ariana_grande_photo_jon_kopaloff_getty_images_465687098.jpg" alt="" class="img-responsive">
                <div class="caption">
                  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.
                </div>                
            </div>  
        </a>  
    </div>              
</div>

如何使这段代码看起来像上图中的代码。

最佳答案

我相信您遇到的问题与您重复使用 .thumbnail 有关。 .您正在将其应用于 <div><img>并且您的 jQuery 脚本尝试应用 maxHeight对两者。

如果我们将您的代码修改为如下所示:

$( document ).ready(function() {
    var heights = $(".thumbnail").map(function() {
        return $(this).height();
    }).get(),

    maxHeight = Math.max.apply(null, heights);

    $(".thumbnail").height(maxHeight);
});
.thumbnail {
  overflow: hidden;
}

.thumbnail img {
  height: auto;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<div class="container">
  <div class="row">
    <div class="col-xs-3">
      <a href="#">
        <div class="thumbnail">
          <img src="http://ksassets.timeincuk.net/wp/uploads/sites/55/2017/11/GettyImages-873359588-920x584.jpg" alt="osooabina"  class="img-responsive">
          <div class="caption">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.</div>                
        </div>
      </a>
    </div>    
    
    <div class="col-xs-3">
      <a href="#">
        <div class="thumbnail">
          <img src="https://i.pinimg.com/736x/22/5e/80/225e80ea57b247c188ac160ed34fe3cf--ariana-grande-tattoos-ariana-grande-no-makeup.jpg" alt="" class="img-responsive">
          <div class="caption">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.</div>
        </div>  
      </a>
    </div>    

    <div class="col-xs-3">
      <a href="#">
        <div class="thumbnail">
          <img src="http://gazettereview.com/wp-content/uploads/2015/12/Eminem-Featured-image.jpg" alt="osooabina"  class="img-responsive">
          <div class="caption">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.</div>
        </div>
      </a> 
    </div>  

    <div class="col-xs-3">
      <a href="#">
        <div class="thumbnail">
          <img src="https://www.biography.com/.image/t_share/MTQ3MzM3MTcxNjA5NTkzNjQ3/ariana_grande_photo_jon_kopaloff_getty_images_465687098.jpg" alt="" class="img-responsive">
          <div class="caption">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,.</div>
        </div>
      </a> 
    </div>  
  </div>
</div>

您会得到更类似于您的源图像的东西。请注意,这并没有解决实际图像尺寸相同的问题;它只是确保您的 .thumbnail wrapper 的高度都相同。

我还建议您将其转换为在页面加载时和发生窗口调整大小事件时运行的函数。

关于javascript - 当我裁剪照片时,它们最终将标题隐藏在缩略图中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47413978/

相关文章:

javascript - Node js 请求和 cheerio 等待页面完全加载

javascript - 如何构建一个 jQuery 对话框以确认(是/否),它可以在应用程序的任何地方工作?

javascript - 文件正在自动提交

jquery ajax成功问题

php - 为什么我的子主题不使用新的 style.css 文件?

javascript - 超时 - php 脚本期间加载程序

javascript - 它在 end_time 中给了我 unsefined(NaN) 那么我该如何解决这个问题

c# - ASP.NET WebForms 中的 SignalR

javascript - 如何在特定的div中执行脚本

php - 如何防止页面重新加载/刷新提交ajax调用表单并获取文本和上传的文件/图像?