求下面 js能封装吗。像JQ一样拿来用
var startX,startY; //初始坐标
document.ontouchstart = function(e){
var ev = e || event.window;
var touch = ev.touches[0];
startX = touch.pageX;
startY = touch.pageY;
document.ontouchmove = function(e){
var ev = e || event.window;
var touch = ev.touches[0];
var touX = touch.pageX;
var touY = touch.pageY;
document.ontouchend = function(e){
if(touX - startX > 30){ alert('向右移动')}else if( touX - startX < -30){ alert('向左移动')}
}
}
}
------解决方案--------------------function Box(){
this.zuo = '左';
this.you = '右';
this.xz = function(){//向左
alert(this.zuo)
};
this.xy = function(){//向右
alert(this.you)
};
}
var box = new Box();
box.xz();