Here is the code I'm using
$(document).on("mousemove touchmove",function(e){
var currentY = e.originalEvent.touches ? e.originalEvent.touches[0].clientY : e.clientY;
var currentX = e.originalEvent.touches ? e.originalEvent.touches[0].clientX : e.clientX;
//do stuff with the coordinates
});
It works perfectly fine, however there is some lag on mobile devices (tested on Android).
The cause of the lag is the navigation bar, at the top of mobile browsers (e.g. Chrome on Android).
If the user scrolls down, the navigation bar goes out of view and the touch events work perfectly.
The code below disables the page from scrolling, and the touch event works perfectly. However, I do not want to prevent the user from scrolling (as it is required)
document.addEventListener('touchmove', function(e) {
e.preventDefault();
}, { passive: false });
How can I prevent the lag when the navigation bar is present?