mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:09:52 +02:00
Scroll element into view if it's been moved off the screen
This commit is contained in:
parent
03da2f0946
commit
1be948ee28
1 changed files with 4 additions and 1 deletions
|
@ -45,12 +45,15 @@
|
||||||
|
|
||||||
function scheduleBringToView(timeout) {
|
function scheduleBringToView(timeout) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
// If the element is not visible because the keyboard has been raised over the top of it, scroll it into view.
|
// If the element is not visible because the keyboard has been raised over the top of it, scroll it up into view.
|
||||||
|
// If the element is not visible because the keyboard raising has moved it off screen, scroll it down into view.
|
||||||
var elementRect = document.activeElement.getBoundingClientRect();
|
var elementRect = document.activeElement.getBoundingClientRect();
|
||||||
var VISUAL_MARGIN = 3
|
var VISUAL_MARGIN = 3
|
||||||
var delta = elementRect.y + elementRect.height + VISUAL_MARGIN - window.innerHeight;
|
var delta = elementRect.y + elementRect.height + VISUAL_MARGIN - window.innerHeight;
|
||||||
if (delta > 0) {
|
if (delta > 0) {
|
||||||
window.scrollBy(0, delta);
|
window.scrollBy(0, delta);
|
||||||
|
} else if (elementRect.y < VISUAL_MARGIN) {
|
||||||
|
window.scrollBy(0, elementRect.y - VISUAL_MARGIN);
|
||||||
}
|
}
|
||||||
}, timeout);
|
}, timeout);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue