移动端轮播插件Swipe.js 2.0 优化
来源:互联网 发布:淘宝网个人中心 编辑:程序博客网 时间:2024/06/05 17:23
优化点:
1.手动循环拖动
2.触摸后依旧自动播放
插件本身不支持手动话滑动的循环播放
可以在插件js源代码中找到代码
var events={}中关于end:事件的处理,如下代码:
end: function(event) { // measure duration var duration = +new Date - start.time; // determine if slide attempt triggers next/prev slide var isValidSlide = Number(duration) < 250 // if slide duration is less than 250ms && Math.abs(delta.x) > 20 // and if slide amt is greater than 20px || Math.abs(delta.x) > width/2; // or if slide amt is greater than half the width // determine if slide attempt is past start and end var isPastBounds = !index && delta.x > 0 // if first slide and slide amt is greater than 0 || index == slides.length - 1 && delta.x < 0; // or if last slide and slide amt is less than 0 // determine direction of swipe (true:right, false:left) var direction = delta.x < 0; // if not scrolling vertically if (!isScrolling) { if (isValidSlide && !isPastBounds) { if (direction) { move(index-1, -width, 0); move(index, slidePos[index]-width, speed); move(index+1, slidePos[index+1]-width, speed); index += 1; } else { move(index+1, width, 0); move(index, slidePos[index]+width, speed); move(index-1, slidePos[index-1]+width, speed); index += -1; } options.callback && options.callback(index, slides[index]); } else { //触摸滑动时实现循环播放 if(isPastBounds){ if (index == 0) { slide(slides.length - 1); } else { slide(0); } }else{ move(index-1, -width, speed); move(index, 0, speed); move(index+1, width, speed); } } } // kill touchmove and touchend event listeners until touchstart called again element.removeEventListener('touchmove', events, false) element.removeEventListener('touchend', events, false) },注意else 分支中的代码注释,新增的代码实现了手动滑动循环播放的效果
如果想要实现手动滑动后,继续自动播放,那么修改stop()函数 如下:
function stop() { //delay = 0; delay = options.auto > 0 ? options.auto : 0; clearTimeout(interval ); }
0 0
- 移动端轮播插件Swipe.js 2.0 优化
- Swipe-移动端触摸滑动插件swipe.js
- 移动web滑动效果Swipe JS插件
- swipe.js移动端滑动插件
- 移动开发中的上下左右滑动插件jquery.swipe.js
- Swipe.js插件介绍
- Swipe JS滑动插件
- swipe js插件
- swipe js插件使用
- swipe.js插件相关用法
- 移动开发中的上下左右滑动插件jquery.swipe.js非常经典的啊!
- 移动端h5轮播插件swipe
- 【仅支持移动设备】Swipe.JS轻量级移动幻灯效果
- Swipe JS
- 移动Web内容滑块 – Swipe JS
- 移动端触屏切换Swipe.js 中文API手册
- 初识swipe.js
- touch.js-swipe
- 【Oracle篇】常用查询与SQL92笔记(一)
- 【Android】编程规范与常用技巧
- nginx 学习八 高级数据结构之基数树ngx_radix_tree_t
- 你是大河马的合格地方
- 单片机读取SD卡中BMP图片文件并送往TFT彩屏上显示(测试成功)(一)
- 移动端轮播插件Swipe.js 2.0 优化
- html页面中打印样式
- 黑魔法__attribute__((cleanup))
- TCP的三次握手、四次挥手
- 教你创建高大上的多边形字体
- matlab产生随机数
- how to add Javascript and CSS in page layout with sharepoint 2013
- struts 2 的SessionAware接口使用
- 检测当前是否联网