我有一堆列組(col-md-4),每個組包含兩個絕對定位的圖像在一個div內彼此的頂部。我需要通過將其不透明度從0更改爲1(基於哪個單選按鈕被選中)來切換組中的可見圖像。有沒有辦法做到這一點與jQuery?如何根據選擇哪個單選按鈕來交換顯示的圖像?
<div class="row">
<div class="col-md-4">
<div class="slide-swapper">
<img src="images/gray.jpg" class="img-fluid gray" height="360" width="360" alt="gray">
<img src="images/silver.jpg" class="img-fluid silver" height="360" width="360" alt="silver">
</div>
<div class="color-group">
<input id="input-1" type="radio" checked="checked" name="change-image">
<label for="input-1" title="gray">Gray</label>
<input id="input-2" type="radio" name="change-image">
<label for="input-2" title="silver">Silver</label>
</div>
</div>
</div>
<style>
.slide-swapper {
position: relative;
height: 360px;
margin-bottom: 30px;
}
img {
position: absolute;
top: 0;
left: 0;
}
</style>
對不起,但這對我不起作用。我需要某種動態解決方案,因爲我有一大堆這些列組。 –
@GoranTesic好的,請參閱最新版本。 – Mike
這會同時更改所有col-md-4組中的圖像。有沒有一種方法只針對來自單選按鈕所屬的col-md-4組的圖像? –