This i believe from what I've researched and read will need an API.
I have found some code on the subject and a link to where you can understand how this API works. I think if I understand your question, this will be a solution:
let pendingUpdate = false;
function viewportHandler() {
if (pendingUpdate) return;
pendingUpdate = true;
requestAnimationFrame(() => {
pendingUpdate = false;
var layoutViewport = document.getElementById('layoutViewport');
// Since the bar is position: fixed we need to offset it by the
// visual viewport's offset from the layout viewport origin.
var offsetLeft = viewport.offsetLeft;
var offsetTop = viewport.height
- layoutViewport.getBoundingClientRect().height
+ viewport.offsetTop;
// You could also do this by setting style.left and style.top if you
// use width: 100% instead.
bottomBar.style.transform = 'translate(' +
offsetLeft + 'px,' +
offsetTop + 'px) ' +
'scale(' + 1/viewport.scale + ')'
}
}
window.visualViewport.addEventListener('scroll', viewportHandler);
window.visualViewport.addEventListener('resize', viewportHandler);
Check it out: https://developer.mozilla.org/en-US/docs/Web/API/Visual_Viewport_API