Solve the problem that the page content is blocked or the new page scroll position is incorrect due to the ios elastic mechanism or the navigation bar at the top of the browser fixed for page jump

Posted May 27, 20201 min read

const scrollToTop =() => {
if(!isAndroidApp) {
window.scrollTo(0, 0);
const inp = document.getElementsByTagName("input");
if(!isApp && inp.length > 0) {
let scrollTopCurrent:any = "";
window.addEventListener("scroll",() => {
var scrollTop = window.pageYOffset || document.body.scrollTop;
if(scrollTop > 0) {
scrollTopCurrent = scrollTop;
}
});
Array.from(inp).map(item => {
item.onblur =() => {
window.scrollTo(0, 0);
};
item.onfocus =() => {
window.scrollTo(0, scrollTopCurrent);
};
});
}
}
}