Last active
May 28, 2018 07:18
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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