javascript - JQuery 等高行

标签 javascript jquery html css row

我希望使用 JQuery 创建具有 div 的相同高度和行。我卡住了!

关于如何使第一行等于第二行的任何想法?我找到了一个我想要的例子 here当您取消单击“按行”时,所有行都变得相等。只是不确定如何。

jQuery(document).ready(function($) {

equalheight = function(container){

var currentTallest = 0,
     currentRowStart = 0,
     rowDivs = new Array(),
     $el,
     topPosition = 0;
 $(container).each(function() {

   $el = $(this);
   $($el).height('auto')
   topPostion = $el.position().top;

   if (currentRowStart != topPostion) {
     for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
       rowDivs[currentDiv].height(currentTallest);
     }
     rowDivs.length = 0; // empty the array
     currentRowStart = topPostion;
     currentTallest = $el.height();
     rowDivs.push($el);
   } else {
     rowDivs.push($el);
     currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
  }
   for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
     rowDivs[currentDiv].height(currentTallest);
   }
 });
}


$(window).load(function() {
  equalheight('.main article');
});

$(window).resize(function(){
  equalheight(' article');
});
	});
.landingpage .main article {
  float: left;
  width: 29.33%;
  background: #ccc;
  margin: 10px 1%;
  padding: 1%;
}

@media all and (max-width: 800px) {
.landingpage .main article {
    width: 100%
  }
<div class="landingpage">
<section class="main">
  <article>CPR & AED Classes <BR>1 </article>
  <article>CPR & First Aid Classes</article>
  <article>BLS Classes<BR>1</article>
  <article>EMSA Pediatric Classes</article>
  
    <article>Instructor Training  </article>
  <article>Water Safety<BR>1<BR>1</article>
  
</section>

</div>

最佳答案

试试这个

$(document).ready(function(){
    maxheight=0;
    $('.main article').each(function(){
        maxheight = $(this).height() > maxheight ? $(this).height() : maxheight;
    })
    $('.main article').height(maxheight);
});

这将使所有行高相同,成为行的最大高度

working example

关于javascript - JQuery 等高行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35308876/

相关文章:

javascript - 控制jquery模态对话框灰色部分的类名

javascript - 如何使用 Javascript 获取 'css-pixel'(媒体查询)宽度?

javascript - 如何在 React 中将我的子组件移动到新的父组件?

javascript - 下拉+用户输入(文本)

javascript - 随机彩色文本jquery

javascript - 引用被设置为异步的属性

javascript - 使用 JavaScript 获取元素的样式

javascript - setInterval() 不适用于制作数字时钟

javascript - 有条件处理ajax请求

c# - Bootstrap CSS 不适用于 ASP.net