【发布时间】:2022-01-21 16:39:42
【问题描述】:
我使用的是通用引导轮播,但每张幻灯片包含 2 列。我正在尝试使旋转木马幻灯片都具有相同的高度。因此,如果一张幻灯片的内容更多,则其他幻灯片会调整到此高度:
<div id="carouselExampleInterval" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active" data-bs-interval="5000">
<div class="container">
<div class="row justify-content-center">
<div class="col-xl-6 align-self-center">
test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test
</div>
<div class="col-xl-4">
test
</div>
</div>
</div>
</div>
<div class="carousel-item white" data-bs-interval="5000">
<div class="container">
<div class="row justify-content-center">
<div class="col-xl-6 align-self-center">
test
</div>
<div class="col-xl-6">
test
</div>
</div>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
我尝试了以下 jQuery 代码,但在移动设备上检查时似乎不起作用:
<script>
function carouselNormalization() {
var items = $('#carouselExampleInterval .item'),
heights = [],
tallest;
if (items.length) {
function normalizeHeights() {
items.each(function() {
heights.push($(this).height());
});
tallest = Math.max.apply(null, heights);
items.each(function() {
$(this).css('min-height', tallest + 'px');
});
};
normalizeHeights();
$(window).on('resize orientationchange', function() {
tallest = 0, heights.length = 0;
items.each(function() {
$(this).css('min-height', '0');
});
normalizeHeights();
});
}
}
window.onload = function() {
carouselNormalization();
}
</script>
【问题讨论】:
-
检查这个:codepen.io/mohan-aiyer/pen/MzgvbN。希望对您有所帮助。
标签: javascript jquery css twitter-bootstrap