2016-05-12 52 views
1

默認情況下,指標水平的底部,分別對齊,垂直排列的指標,引導旋轉木馬

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> 
 
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> 
 
    <!-- Indicators --> 
 
    <ol class="carousel-indicators"> 
 
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> 
 
    <li data-target="#carousel-example-generic" data-slide-to="1"></li> 
 
    <li data-target="#carousel-example-generic" data-slide-to="2"></li> 
 
    </ol> 
 

 
    <!-- Wrapper for slides --> 
 
    <div class="carousel-inner" role="listbox"> 
 
    <div class="item active"> 
 
     <img src="..." alt="..."> 
 
     <div class="carousel-caption"> 
 
     ... 
 
     </div> 
 
    </div> 
 
    <div class="item"> 
 
     <img src="..." alt="..."> 
 
     <div class="carousel-caption"> 
 
     ... 
 
     </div> 
 
    </div> 
 
    ... 
 
    </div> 
 

 
    <!-- Controls --> 
 
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> 
 
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 
 
    <span class="sr-only">Previous</span> 
 
    </a> 
 
    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> 
 
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
 
    <span class="sr-only">Next</span> 
 
    </a> 
 
</div>

什麼是垂直對齊的各項指標最好的辦法,使各項指標總是均勻分佈在傳送帶內使用的圖像的高度,每個指示符的空間相等?我注意到編號爲carousel-example-generic的元素的高度根據傳送帶內使用的圖像而變化,這是由於css屬性(可能是默認值)height: auto;

是否應使用式,看起來像:元件的

高度與指標carousel-example-generic /量=指示器的高度的一個id?

我應該使用JavaScript來實現我在這裏要求的嗎?

我想要達到這樣的效果JSFiddle,但我不想爲我的指標使用固定高度的數字,我希望它們始終使用它們可以在旋轉木馬中使用的全部空間。

編輯:我的猜測是,指標的高度應該用我在以下JSFiddle中顯示的公式計算。

回答

0

首先你刪除或註釋左,右控制

.carousel-indicators li{ 
display: block; 
width: 10px; 
height: 10px; 
margin-bottom: 10px; 
} 

.carousel指標李顯示爲 'inline-block的' 是改變 '塊' 指標顯示垂直

.carousel-indicators .active { 
width: 12px; 
height: 12px; 
margin-bottom: 10px; 
background-color: #fff; 
} 

給空間對於指標來說,設置margin-bottom是10px,活動類別也是

.carousel-indicators{ 
height: 350px; 
display: table-cell; 
vertical-align: middle; 
float: none; 
} 

指標顯示爲您的圖像大小設置中間高度(滑塊)

+0

但現在的指標只有10個像素的高度。我希望他們儘可能高,他們可以在旋轉木馬內,同時在彼此的上方(或下方),同時適合旋轉木馬的高度(這僅在使用(例如佔位符)圖像之後可用)整體控制將是(在這個例子中)'2 * 10px + 1 * 12px = 32px',但是如果圖像高度高於32px?我仍然希望它們很好地適合。我希望你明白我在這裏要求的。 – Barrosy

+0

你增加高度和寬度,不會影響圖像 –

+0

不會增加指標的高度意味着當圖像的高度小於指標總高度乘以高度時它們將伸展超出傳送帶的底部,一旦旋轉木馬進入一個這樣的圖像? – Barrosy

0

您可以使用javascript實現結果。

您可以讀取傳送帶的高度併除以li元素編號。

var carouselHeight = $("#carousel-example-generic").css("height"); 
    var elements = $("#carousel-example-generic li").length; 
    var indicatorHeight = Math.floor(Number(carouselHeight.replace("px", ""))/elements); 

    $("#carousel-example-generic .carousel-indicators li").css("height", indicatorHeight + "px"); 

我做了一個簡單的JSFiddle

+0

我認爲你的答案接近我想達到的目標,但是我們在這裏提到一個調整大小,當轉盤轉到另一個圖像時,轉盤高度可能會改變。我想在這裏添加一個調整大小的jquery函數?我會嘗試自己添加它,看看它會如何結果並添加到您的答案,如果我得到它的工作。 – Barrosy

+0

不知怎的,我無法讓'.resize()'工作:https://jsfiddle.net/fp1nfcbe/4/,現在它說'alert(...)'它應該再次設置變量並調整高度再次。 – Barrosy

+0

看看這個lib可以幫助你[css-element-queries](http://marcj.github.io/css-element-queries/) – Max