javascript – jquery-match-height不能在第一行工作

前端之家收集整理的这篇文章主要介绍了javascript – jquery-match-height不能在第一行工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的网站上使用 jquery-match-height插件.

我不明白为什么插件在第一行不起作用.看起来插件试图输出样式高度,但第一行为空.第二排工作正常

HTML

  1. <div class="container">
  2.  
  3. <div class="row article-Box-list">
  4. <div class="col-xs-12 col-md-8 article-Box">
  5. <a href="#"><img src="http://dummyimage.com/768x410/000/fff" alt="" class="img-responsive"></a>
  6.  
  7. <div class="well well-white">
  8. <h2><a href="#">Lorem ipsum dolor sit amet,consectetuer adipiscing elit</a></h2>
  9. <p>Lorem ipsum dolor sit amet,consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Lorem ipsum dolor sit amet,consectetuer adipiscing elit. Aenean commodo ligula eget dolor. <a href="#">More</a></p>
  10. </div>
  11. </div>
  12.  
  13.  
  14. <div class="col-xs-12 col-md-4 article-Box">
  15. <a href="#"><img src="http://dummyimage.com/768x853/000/fff" alt="" class="img-responsive"></a>
  16.  
  17. <div class="well well-white">
  18. <h4><a href="#">Lorem ipsum dolor sit amet,consectetuer.</a></h4>
  19. <p>Lorem ipsum dolor sit amet,consectetuer adipiscing elit. Aenean commodo ligula eget dolor. <a href="#">More</a></p>
  20. </div>
  21. </div>
  22. </div><!-- /first-row-->
  23.  
  24.  
  25.  
  26.  
  27. <div class="row article-Box-list">
  28.  
  29. <div class="col-xs-12 col-md-4 article-Box">
  30. <a href="#" class="img-link"><img src="http://dummyimage.com/768x585/000/fff" alt="" class="img-responsive"></a>
  31.  
  32. <div class="well well-white">
  33. <h4><a href="#">Lorem ipsum dolor sit amet,consectetuer.</a></h4>
  34. <p>Lorem ipsum dolor sit amet,consectetuer adipiscing elit. <a href="#">More</a></p>
  35. </div>
  36. </div>
  37.  
  38.  
  39.  
  40. <div class="col-xs-12 col-md-4 article-Box">
  41. <a href="#" class="img-link"><img src="http://dummyimage.com/768x585/000/fff" alt="" class="img-responsive"></a>
  42.  
  43. <div class="well well-white">
  44. <h4><a href="#">Lorem ipsum dolor sit amet,consectetuer.</a></h4>
  45. <p class="ingress">Lorem ipsum dolor sit amet,consectetuer adipiscing elit. Lorem ipsum dolor sit amet,consectetuer adipiscing elit.<a href="#">More</a></p>
  46. </div>
  47. </div>
  48.  
  49.  
  50. <div class="col-xs-12 col-md-4 article-Box">
  51. <a href="#" class="img-link"><img src="http://dummyimage.com/768x585/000/fff" alt="" class="img-responsive"></a>
  52.  
  53. <div class="well well-white">
  54. <h4><a href="#">Lorem ipsum dolor sit amet,consectetuer. <a href="#">More</a></p>
  55. </div>
  56. </div>
  57.  
  58.  
  59.  
  60. </div><!--/ last-row-->
  61.  
  62.  
  63. </div>

JS

  1. $(function() {
  2. $('.article-Box .well').matchHeight();
  3. });

我的bootply:view(似乎没有工作atm)

我的jsfiddle:view

任何人都知道如何解决这个问题?

解决方法

Samus的 answer实际上是相当接近的,但是你想要的是:

>匹配每行内的.article-Box .well元素的高度
>每排都有不同匹配的高度

事实上,插件只是承诺:

matchHeight makes the height of all selected elements exactly equal

解决方案是单独选择每行中的元素,并将插件分别应用于每个集合,如下所示:

  1. $(function() {
  2. $('.row').each(function(i,elem) {
  3. $(elem)
  4. .find('.article-Box .well') // Only children of this row
  5. .matchHeight({byRow: false}); // Row detection gets confused so disable it
  6. });
  7. });

你可以在this的工作中看到这个更新到你的jsFiddle.您将注意到第一排中的井,而第二列中的井是不同的高度,但是如果您使用浏览器的开发工具检查它们,则在每一行中相同.

猜你在找的jQuery相关文章