最近在使用的一个移动触摸滑动插件Swiper,功能很强大,跟以前的那个swipe.JS相比,同时支持在PC端滑动,支持上下方向滑动,支持多张图片滑动,支持多屏滑动,凡是你想获得的几乎均可以实现。最近做者还更新了3.0版本,优先支持ios和最新版的Android移动端。javascript
能够在github上下载:https://github.com/nolimits4web/Swiper/css
或者有bower的,直接安装 $ bower install swiper
html
<!DOCTYPE html> <html lang="en"> <head> ... <link rel="stylesheet" href="path/to/swiper.min.css"> </head> <body> ... <script src="path/to/swiper.min.js"></script> </body> </html>
jQuery方式jquery
<!DOCTYPE html> <html lang="en"> <head> ... <link rel="stylesheet" href="path/to/swiper.min.css"> </head> <body> ... <script src="path/to/jquery.js"></script> <script src="path/to/swiper.jquery.min.js"></script> </body> </html>
html代码android
<!-- Slider main container --> <div class="swiper-container"> <!-- Additional required wrapper --> <div class="swiper-wrapper"> <!-- Slides --> <div class="swiper-slide">Slide 1</div> <div class="swiper-slide">Slide 2</div> <div class="swiper-slide">Slide 3</div> ... </div> <!-- If we need pagination --> <div class="swiper-pagination"></div> <!-- If we need navigation buttons --> <div class="swiper-button-prev"></div> <div class="swiper-button-next"></div> <!-- If we need scrollbar --> <div class="swiper-scrollbar"></div> </div>
CSS代码ios
.swiper-container { width: 600px; height: 300px; }
js代码git
<script> var mySwiper = new Swiper ('.swiper-container', { // Optional parameters direction: 'vertical', loop: true, // If we need pagination pagination: '.swiper-pagination', // Navigation arrows nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', // And if we need scrollbar scrollbar: '.swiper-scrollbar', }) </script>
jQuery代码github
$(document).ready(function () { //initialize swiper when document ready var mySwiper = new Swiper ('.swiper-container', { // Optional parameters direction: 'vertical', loop: true }) });