Last active
June 21, 2019 01:40
-
-
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)
This file contains 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
// 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