var dTX, dTY, fTX, fTY;
var seuil = 75; 
var swG = () => { document.getElementById("pagsui").click(); };
var swD = () => { document.getElementById("pagpre").click(); };
window.onload = function () {
 window.addEventListener
 ('touchstart', function (event) {
  dTX = event.touches[0].clientX;
  dTY = event.touches[0].clientY;
 });
 window.addEventListener
 ('touchend', function (event) {
  fTX = event.changedTouches[0].clientX;
  fTY = event.changedTouches[0].clientY;
  handleTouch(dTX, fTX, swG, swD);
 });
};
function handleTouch(startX, endX, onswG, onswD) {
 var horD = fTX - dTX;
 var verD = fTY - dTY;
 if (Math.abs(horD) > Math.abs(verD) && Math.abs(horD) > seuil) {
  if (fTX - dTX < 0) {
   onswG(); 
  } else {
   onswD(); 
  }
 }
}
document.onkeydown = function (e) {
 switch (e.key) {
  case 'ArrowLeft': document.getElementById("pagpre").click();
   break;
  case 'ArrowRight': document.getElementById("pagsui").click();
   break;
 }
};