手機UC禁止左右滑動切頁
阿新 • • 發佈:2019-01-11
手機UC 左右滑動時會切換頁面,禁止的方法其一為阻止【document】的 【touchmove】事件 的預設操作,
其次就是呼叫,UC API 程式碼如下:
var xStart,xEnd,yStart,yEnd; document.addEventListener('touchmove',function(evt){ xEnd=evt.touches[0].pageX; yEnd=evt.touches[0].pageY; Math.abs(xStart-xEnd)> Math.abs(yStart-yEnd)&&evt.preventDefault(); },false); document.addEventListener("touchstart",function(evt){ xStart=evt.touches[0].pageX; yStart=evt.touches[0].pageY; },false); ========================= 或者 =====================================
if(navigator.control&&navigator.control.gesture){ navigator.control.gesture(false); }