gpt4 book ai didi

javascript - JQuery 等高行

转载 作者:可可西里 更新时间:2023-11-01 13:50:31 25 4
gpt4 key购买 nike

我希望使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com