swiper组件的使用

作者:zccst

swiper使用过程中不断踩坑,有时一个很小的问题,如果自己实现的话会花很长时间,但其实api都有,所以多研究api,网上查一下别人使用过程中遇到的类似问题,就可以大大缩短开发时间。特此记录一下

2,是否能够检测到滑动方向?
可以。使用swiper.touches里的坐标差值来判断
Object {startX: 171, startY: 254, currentX: 198, currentY: 282, diff: 27}

判断逻辑
swiper.isBeginning && (swiper.touches.currentX - swiper.touches.startX) > 0
批注:也找到比较笨的方法,差一点使用了,原理是根据触摸的起始位置判断。

/**
obj:触发元素;
dir:期望触发方向;'up','down','left','right'
fn :触发后的回调函数
*/
var touchEvent = function(obj,dir,fn){
this.pos = {x:0,y:0};//开始触发位置
var me = this;
obj.addEventListener('touchstart',function(event){
var touch = event.touches[0];
me.pos.x = touch.pageX;
me.pos.y = touch.pageY;
},false);
obj.addEventListener('touchmove',function(event){
var touch = event.touches[0];
me.curtouch = {
x:touch.pageX,
y:touch.pageY
}
},false);
obj.addEventListener('touchend',function(event){
if(me.checkDirV(me.pos,me.curtouch)==dir ||me.checkDirH(me.pos,me.curtouch)==dir){
(typeof fn=='function')&&fn();
}
},false);
}
touchEvent.prototype = {
posdiff:100,//触发敏感度
checkDirV:function(a,b){
return Math.abs(a.y-this.posdiff)>b.y?(a.y>b.y?'up':'down'):'';
},
checkDirH:function(a,b){
return Math.abs(a.x-this.posdiff)>b.x?(a.x>b.x?'left':'right'):'';
}
}


1,是否能够向前追加slide(s)时,不跳动(仍显示当期slide)?
答:Yes, you can, just call swipeTo/swipeNext/swipePrev right after slide prepend
链接:[url]https://github.com/nolimits4web/Swiper/issues/276[/url]


如果您觉得本文的内容对您的学习有所帮助,您可以微信:
[img]http://dl2.iteye.com/upload/attachment/0109/0668/fb266dfa-95ca-3d09-b41e-5f04a19ba9a1.png[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值