/** * 移动端触摸滑动 * @ author 鹿文学 * @ date 2017年5月19日 * 必须先引入 jQuery * 需要滑动的控件(例如 elem )需加类名 touch; 例如使用 slider.init('.elem') */ ;var slider=function(b,c){c.touch=function(){return"ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch};c.init=function(a){a=b(a);c.touch()&&b.each(a,function(a,b){b.addEventListener("touchstart",c.events,!1)})};c.events={goal:null,endPos:{x:0,y:0},handleEvent:function(a){target=a.target;b(target).hasClass("touch")?this.goal=target:this.goal=b(target).closest(".touch")[0];"touchstart"==a.type?this.start(a):"touchmove"==a.type?this.move(a):"touchend"==a.type&&this.end(a)}, start:function(a){a=a.targetTouches[0];startPos={x:a.pageX,y:a.pageY,time:+new Date};isScrolling=0;this.goal.addEventListener("touchmove",this,!1);this.goal.addEventListener("touchend",this,!1)},move:function(a){if(!(1a.x&&b(this.goal).addClass("cur"));this.goal.removeEventListener("touchmove",this,!1);this.goal.removeEventListener("touchend",this,!1)}};return c}(jQuery,window.slider||{});