Skip to content

Instantly share code, notes, and snippets.

@souljorje
Last active May 28, 2018 07:18
Show Gist options
  • Save souljorje/14cbf9b226c0c896cebfb9434a15868b to your computer and use it in GitHub Desktop.
Save souljorje/14cbf9b226c0c896cebfb9434a15868b to your computer and use it in GitHub Desktop.
Fix for page scrolling issue on iOS on input focus in fixed element.
open() {
const offset = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
document.body.style.top = (offset * -1) + 'px';
document.body.classList.add('iOS-scroll-fix');
}
close() {
const offset = parseInt(document.body.style.top, 10);
document.body.classList.remove('iOS-scroll-fix');
document.body.style.top = 0;
window.scrollY = (offset * -1);
document.documentElement.scrollTop = (offset * -1);
document.body.scrollTop = (offset * -1);
}
.iOS-scroll-fix {
position: fixed;
top: 0;
left: 0;
width: 100vw;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment