PetHouse(2016)練習2

範例結果

六、Slider_Carousel

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

確認項目:

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

2.自訂【data-*】 屬性

3.Carousel 加入Swipe事件

<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 class="img img-responsive" src="img/slider/slider04.jpg" />
            <div class="carousel-caption">
                <h3>可愛動物一</h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam tenetur corrupti reiciendis animi natus, quis voluptatum similique asperiores blanditiis aspernatur cum saepe ipsam quo. Consequatur at cumque similique numquam quas!</p>
            </div>
        </div>
        <div class="item">
            <img class="img img-responsive" src="img/slider/slider05.jpg" />
            <div class="carousel-caption">
                <h3>可愛動物一</h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam tenetur corrupti reiciendis animi natus, quis voluptatum similique asperiores blanditiis aspernatur cum saepe ipsam quo. Consequatur at cumque similique numquam quas!</p>
            </div>
        </div>
        <div class="item">
            <img class="img img-responsive" src="img/slider/slider06.jpg" />
            <div class="carousel-caption">
                <h3>可愛動物一</h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam tenetur corrupti reiciendis animi natus, quis voluptatum similique asperiores blanditiis aspernatur cum saepe ipsam quo. Consequatur at cumque similique numquam quas!</p>
            </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>
</div>

Carousel 加入Swipe事件

參考連結

S1.至jQuery Mobile官網,下載swipe等Touch事件(直接下載)

S2寫入jQuery

$(".carousel").swiperight(function() {  
  $(this).carousel('prev');  
});  
$(".carousel").swipeleft(function() {  
  $(this).carousel('next');  
});