このページでは、Bootstrap カルーセルに 3 件のレビューが表示されます。レビューのページをめくる<div>
と、灰色の背景の がレビューの長さに合わせてサイズ変更されます。これは、レビュー リストの最後をラップするまではかなりうまく機能します。
たとえば、[次へ] ボタンを使用してレビューを進めた場合、最後のレビュー (#3) から最初のレビューに移動すると、最初のレビューの下に大きな空白が残ります。同様に、前のボタンを使用してレビューをさかのぼる場合、最初のレビューから最後のレビュー (#3) に移動すると、レビューのテキストが含まれている div からはみ出します (下のスクリーンショットを参照)。
要約すると、前のボタンを使用して #1 から #3 に移動するか、次のボタンを使用して #3 から #1 に移動することにより、レビューのリストをラップするたびに、含まれる div のサイズが正しく変更されません。
ユーザーがこのカルーセルを介してページネーションを行ったときに呼び出されるイベント ハンドラーは、ページの下部にあります (便宜上、ここで再現しています)。
$(document).ready(function () {
$('#reviewsCarousel').carousel({
interval:null
});
// reviewsCarousel height animation and review counter (set .reviewCount to
// the amount of .item in #reviewsCarousel, on .nextReview or .prevReview button
// clicks: set the carousel-inner class to the animate to the height of the next
// item or the first item if there is no next item, on carousel slide, set the
// reviewIndex class text to the index position of the .active .item)
$("#reviewsCarousel .reviewCount").html($('#reviewsCarousel .item').length);
$("#reviewsCarousel .btn.nextReview").click(function () {
var reviewHeight = $("#reviewsCarousel .item.active").next(".item").height();
if (reviewHeight === undefined) {
var reviewHeight = $("#reviewsCarousel .item").first(".item").height();
}
$("#reviewsCarousel .carousel-inner").animate({"height":reviewHeight + "px"}, 400);
$('#reviewsCarousel').bind('slid', function () {
$("#reviewsCarousel .reviewIndex").html($("#reviewsCarousel .active").index("#reviewsCarousel .item") + 1);
});
});
$("#reviewsCarousel .btn.prevReview").click(function () {
var reviewHeight = $("#reviewsCarousel .item.active").prev(".item").height();
if (reviewHeight === undefined) {
var reviewHeight = $("#reviewsCarousel .item").last(".item").height();
}
$("#reviewsCarousel .carousel-inner").animate({"height":reviewHeight + "px"}, 400);
$('#reviewsCarousel').bind('slid', function () {
$("#reviewsCarousel .reviewIndex").html($("#reviewsCarousel .active").index("#reviewsCarousel .item") + 1);
});
});
});
問題を示すスクリーンショットをいくつか示します。