這次用 Bootstrap 來做輪播圖,整體非常簡單。

直接把那段程式碼複製到 WebStorm 裡即可。
下面我會用自己某一次的作業,實際解釋其中各部分分別代表什麼意思(由於這段程式碼的含義老師沒教過,以下是我的自行理解,若有錯誤還請海涵)。

「男友秋裝上新」這個地方就是一個輪播,一共 3 個小圓點,也就是三張圖,可以透過左右箭頭翻動。
接著奉上原始碼,並在程式碼後逐段解釋:
<div class="col-md-9 lunbo"> <div id="carousel-example-generic" class="carousel slide" data-ride="carousel" style="margin-top: 1.4285rem"> <!-- Indicators --> <ol class="carousel-indicators" style="margin-left: -20rem"> <li data-target="#carousel-example-generic" data-slide-to="0" class="active"> </li> 這裡規定播放順序 3個li代表3個小點 點一個小點 就是一張圖 <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"> 這裡是要播放的圖 3張 <div class="item active">這裡的active 對應上面active的那個小圓點 <img src="三組項目/PC/PC首頁/lunbo1.jpg" alt="..." style="width: 64rem;height: 31.9285rem"> <div class="carousel-caption"></div> </div> <div class="item"> <img src="三組項目/PC/PC首頁/lunbo2.jpg" alt="..."style="width: 64rem;height: 31.9285rem"> <div class="carousel-caption"></div> </div> <div class="item"> <img src="三組項目/PC/PC首頁/lunbo3.jpg" alt="..."style="width: 64rem;height: 31.9285rem"> <div class="carousel-caption"></div> </div> </div> <!-- Controls --> 這裡就是那左右兩個箭頭 <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">上翻 <span class="glyphicon glyphicon-chevron-left"></span> </a> <a class="right carousel-control" href="#carousel-example-generic" data-slide="next">下翻 <span class="glyphicon glyphicon-chevron-right"></span> </a> </div> </div>
如果只需要兩張圖,就自行改程式碼——刪掉一個圖片和一個圓點,並調整好圓點那邊的設定即可。
另外,data-slide-to="0" 裡的數字只是舉例,實際情況要自行判斷對應關係。