|
本帖最后由 shancha 于 2016-1-7 11:18 编辑
如题,当按住的时候长按事件已经触发,按住下拉的时候下拉刷新才触发,api提供的setRefreshHeaderInfo只能在回调的时候才能写代码,而回调的时候是松开手才返回,松开手的时候长按事件已经执行完了。。。
长按代码如下:
function press(el,callback){
var t=null;
var num=0;
var touchstartFun=function(){
t=setInterval(function(){
num=num+0.5;
if(num>=1){
//alert("长按");
if(typeof(callback)=="function")callback(el);
else if(typeof(callback)=="string")eval(callback);
clearInterval(t);
}
},500);
}
if(window.event.type=="touchstart"){
touchstartFun();
}
else{
el.ontouchstart=function(){
touchstartFun();
}
}
el.ontouchend=function(){
clearInterval(t);
}
el.ontouchmove=function(){
setTimeout(function(){clearInterval(t)},400);
}
}
|
|