Last active
March 9, 2020 18:58
-
-
Save rjurado01/533362eb522709c9a514efc1b5bedd44 to your computer and use it in GitHub Desktop.
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
const fixScrollToInput = () => { | |
// resize is not finished (body height must be smaller because keyboard) | |
if (document.body.offsetHeight == window.bodyHeight) { | |
setTimeout(fixScrollToInput, 100); | |
} | |
// check if element is hidden by keyboard | |
else if (document.activeElement.getBoundingClientRect().top > document.body.offsetHeight) { | |
document.activeElement.scrollIntoView({behavior: 'smooth', lock: "center"}); | |
} | |
} | |
const calculateBodyHeight = () => { | |
window.bodyHeight = document.body.offsetHeight; | |
if (!window.bodyHeight) setTimeout(calculateBodyHeight, 100); | |
}; | |
document.addEventListener("deviceready", () => { | |
calculateBodyHeight(); | |
window.addEventListener('keyboardDidShow', fixScrollToInput); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment