vue 長按事件?

var timeOutEvent=0;//定時器

html結構:css

<div @touchstart="gtouchstart(v)" @touchmove="gtouchmove()" @touchend="gtouchend(v)"></div>
//開始按
              gtouchstart:function gtouchstart(item){ timeOutEvent = setTimeout(function(){ vm.longPress(item) },500);//這裏設置定時器,定義長按500毫秒觸發長按事件,時間能夠本身改,我的感受500毫秒很是合適
                  return false; }, //手釋放,若是在500毫秒內就釋放,則取消長按事件,此時能夠執行onclick應該執行的事件
              gtouchend:function gtouchend(item){ clearTimeout(timeOutEvent);//清除定時器
                  if(timeOutEvent!=0){ //這裏寫要執行的內容(尤如onclick事件)
 vm.goChat(item); } return false; }, //若是手指有移動,則取消全部事件,此時說明用戶只是要移動而不是長按
              gtouchmove:function gtouchmove(){ clearTimeout(timeOutEvent);//清除定時器
                  timeOutEvent = 0; }, //真正長按後應該執行的內容
              longPress:function longPress(item){ timeOutEvent = 0; //執行長按要執行的內容,如彈出菜單
                  $api.css($api.dom('.Popup'), 'display:block'); }

源地址:https://www.cnblogs.com/imsomnus/p/6429074.htmlhtml

相關文章
相關標籤/搜索