这是一个非常小的一个javascript类库,但功能却不简单,它可以用来展示web页面上的任何内容,支持精确的触摸移动操作,而且还可以设置自动播放、等比例缩放等等实用性的功能。
参见: http://www.jiawin.com/swipe-mobile-touch-slider
http://www.w3cplus.com/mobile/mobile-terminal-refactoring-scroll-with-swipe.html
http://www.jiawin.com/swiper-mobile-touch-slider-js
window.mySwipe = new Swipe(document.getElementById('slider'), { startSlide: 2, //起始图片切换的索引位置,默认为0 speed: 400, //动画执行时间,单位毫秒,默认为300 auto: 3000, //设置自动切换时间,单位毫秒,无默认值 continuous: true, //无限循环的图片切换效果,默认为true disableScroll: false, //阻止由于触摸而滚动屏幕,默认为false stopPropagation: false, //阻止事件冒泡,默认为false callback: function(index, elem) {}, //回调函数,滚动时调用 transitionEnd: function(index, elem) {} //回调函数,滚动的transition动画结束后调用。 });
比较使用的API方法,例如:
prev():上一页
next():下一页
getPos():获取当前页的索引
getNumSlides():获取所有项的个数
slide(index, duration):滑动方法