Swipe2.1更新——移动Web内容滑块

  Swipe JS 是一个轻量级(3.7 kb) mobile slider,支持 1:1 触摸移动(基于精确的触摸位置的内容滑动)。

  但是我使用一段时间后发现两个bug,所以在官方2.0(官网http://swipejs.com/)的基础上我做了一下优化,在这里定义为swipe2.1吧。

  两点优化:

  1、解决触摸滑动结束后停止自动播放的bug(代码分析,这里只提下修复bug的地方);

handleEvent: function(event) {
      switch (event.type) {
        case 'touchstart': this.start(event); break;
        case 'touchmove': this.move(event); break;
        case 'touchend': offloadFn(this.end(event)); //去掉滑动结束后的break
      }

end: function(event) {
     element.removeEventListener('touchmove', events, false);
      element.removeEventListener('touchend', events, false); //在这之后添加
      delay = options.auto;
}

  2、解决不同高度的tab切换是,高度低的tab底部有大量空白的bug(代码分析,这里只提下修复bug的地方);

  

var height, heights = [];
function
setup() {   //前面不变...   container.style.visibility = 'visible'; //在这之后加 container.style.height = slides[index].offsetHeight + 'px';//修复不同高度之间的切换 } function slide(to, slideSpeed) { //前面不变... offloadFn(options.callback && options.callback(index, slides[index])); //在这之后加 setHeight(to); } function setHeight(index){ //修复不同高度之间的切换 if(-1< index && index < slides.length){ height = slides[index].offsetHeight; container.style.height = height + 'px'; } }

  百度分享下载地址 swipe-2.1.min.js

原文地址:https://www.cnblogs.com/ljack/p/3441929.html