一佳一

记录像1+1一样简洁的代码

导航

移动端 图片切换 轮播(banner)

Posted on 2016-04-08 15:08  一佳一  阅读(12342)  评论(1编辑  收藏  举报

发现一个很好用的jquery控件

操作很简单

1.引入css

    <link href="/Resources/style/swiper.min.css" rel="stylesheet" type="text/css" />

2.插入自定义样式

<style>
.swiper-container {
width: 100%;
height: 100%;
}

.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}

.banner img {
width: 100%;
max-height: 300px;
}


</style>

 

3.设置轮播图片

 <div class="swiper-container">
            <div class="swiper-wrapper">
                <div class="swiper-slide"><div class="banner"><img src="/Resources/images/banner.jpg" onclick="alert('1')" /></div></div>
                <div class="swiper-slide"><div class="banner"><img src="/Resources/images/shangping.jpg" /></div></div>
            </div>
            <!-- Add Pagination -->
            <div class="swiper-pagination"></div>
            <!-- Add Arrows -->
            @*<div class="swiper-button-next"></div>
                <div class="swiper-button-prev"></div>*@
        </div>

 

4.底部引入JS文件以及配置

<script src="/Resources/js/swiper.min.js"></script>
<script>
    var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
        paginationClickable: true,
        spaceBetween: 30,
        centeredSlides: true,
        autoplay: 2500,
        autoplayDisableOnInteraction: false
    });
</script>

 

参考资料:

http://www.swiper.com.cn/demo/senior/index.html