You can do this by preventing pointer events on the body and then temporarily allowing them in a document.onclick
handler. Then simulate a click using document.elementFromPoint
(taken from this question). Just add 50
to the offsetX
value of the initial click event.
script:
let $body = $('body');
$body.addClass('locked');
document.onclick = function(e) {
$body.removeClass('locked');
let el = document.elementFromPoint(e.offsetX + 50, e.offsetY);
if (el) {
el.click();
}
$body.addClass('locked');
};
css:
body.locked {
pointer-events: none;
}