Вроде получилось, но выдаётся ошибка.
var el = document.getElementsByTagName('body')[0];
el.addEventListener("touchstart", handleStart, false);
el.addEventListener("touchend", handleEnd, false);
//el.addEventListener("touchmove", handleMove, false);
function handleStart(evt) {
evt.preventDefault();
var touches = evt.changedTouches;
if(window.innerWidth/2 < touches[0].pageX)
button1 = true;
button2 = false;
if(window.innerWidth/2 > touches[0].pageX){
button2 = true;
button1 = false
}
}
function handleEnd(evt) {
evt.preventDefault();
var touches = evt.changedTouches;
if(window.innerWidth/2 < touches[0].pageX)
button1 = false;
button2 = false;
if(window.innerWidth/2 > touches[0].pageX){
button2 = false;
button1 = false
}
}
Вот такая ошибка
[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See
https://www.chromestatus.com/features/5093566007214080