Class(2017-1)練習1

六、【carousels】區塊

BS:【JavaScript】>【輪播效果Carousel】

確認項目:

1.修改過程需要確認【ID名稱的一致性】

2.自訂【data-*】 屬性

3.Carousel 加入Swipe事件

<!-- carousels ===================================================================  -->
<div id="carousel-ADslider" class="carousel slide carousel-fade" data-ride="carousel" data-interval="false">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-ADslider" data-slide-to="0" class="active"></li>
<li data-target="#carousel-ADslider" data-slide-to="1"></li>
<li data-target="#carousel-ADslider" data-slide-to="2"></li>
<li data-target="#carousel-ADslider" data-slide-to="3"></li>
<li data-target="#carousel-ADslider" data-slide-to="4"></li>
<li data-target="#carousel-ADslider" data-slide-to="5"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="images/slider01.jpg" alt="Fn暑假拿證照">
<div class="carousel-caption">
<h3>Fn暑假拿證照</h3>
<p>Fn暑假拿證照內文</p>
</div>
</div>
<div class="item">
<img src="images/slider02.jpg" alt="學習CCNP送CCNA">
<div class="carousel-caption">
<h3>學習CCNP送CCNA</h3>
<p>學習CCNP送CCNA內文</p>
</div>
</div>
<div class="item">
<img src="images/slider03.jpg" alt="Python創新應用實務班">
<div class="carousel-caption">
<h3>Python創新應用實務班</h3>
<p>Python創新應用實務班內文</p>
</div>
</div>
<div class="item">
<img src="images/slider04.jpg" alt="設計無限未來">
<div class="carousel-caption">
<h3>設計無限未來</h3>
<p>設計無限未來內文</p>
</div>
</div>
<div class="item">
<img src="images/slider05.jpg" alt="簡報完全攻略">
<div class="carousel-caption">
<h3>簡報完全攻略</h3>
<p>簡報完全攻略內文</p>
</div>
</div>
<div class="item">
<img src="images/slider06.jpg" alt="Maker機器人程式營">
<div class="carousel-caption">
<h3>Maker機器人程式營</h3>
<p>Maker機器人程式營內文</p>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-ADslider" 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-ADslider" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>

$('.carousel').carousel({
interval: 5000
})

 

Carousel 加入Swipe 觸控事件

參考連結

S1.至jQuery Mobile官網,下載swipe等Touch事件

S2寫入jQuery

<!--  carousel 觸控外掛   -->
<script src="js/jquery.mobile.custom.js"></script>

 

// carousel 觸控外掛程式
$(".carousel").swiperight(function() {
$(this).carousel('prev');
});
$(".carousel").swipeleft(function() {
$(this).carousel('next');
});