Skip to content

Instantly share code, notes, and snippets.

@MoOx
Last active June 21, 2019 01:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MoOx/c26d0950c8c2b25c12220793b60ec9f5 to your computer and use it in GitHub Desktop.
Save MoOx/c26d0950c8c2b25c12220793b60ec9f5 to your computer and use it in GitHub Desktop.
Auto scroll to proper active (form) element when keyboard open (may be useless on iOS, but useful on Android)
// auto scroll to proper active (form) element when keyboard open
// may be useless on iOS, but useful on Android
function scrollToActiveElement() {
if (document.activeElement && document.activeElement.scrollIntoViewIfNeeded) {
document.activeElement.scrollIntoViewIfNeeded()
}
}
window.addEventListener("resize", () => {
setTimeout(scrollToActiveElement, 200)
setTimeout(scrollToActiveElement, 1000) // just in case browser is slow
}, false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment