Save and restore scroll position
* This is a big deal when typing thoughts that are over a page long, it will jump you to the bottom of the input box every time and it's a little jarring.
This commit is contained in:
parent
3c05647689
commit
4c2251a460
|
@ -40,11 +40,15 @@
|
||||||
const textExtEl = document.getElementById("id_extended_text");
|
const textExtEl = document.getElementById("id_extended_text");
|
||||||
|
|
||||||
function updateBoxHeight(box) {
|
function updateBoxHeight(box) {
|
||||||
|
// Save scroll position
|
||||||
|
const scrollY = window.scrollY;
|
||||||
//style.height doesn't include padding, .scrollHeight does
|
//style.height doesn't include padding, .scrollHeight does
|
||||||
box.style.height = "auto";
|
box.style.height = "auto";
|
||||||
// Set overflow hidden to ensure scrollbars aren't shown, since they change the width and thus the height
|
// Set overflow hidden to ensure scrollbars aren't shown, since they change the width and thus the height
|
||||||
box.style.overflow = "hidden";
|
box.style.overflow = "hidden";
|
||||||
box.style.height = box.scrollHeight + "px";
|
box.style.height = box.scrollHeight + "px";
|
||||||
|
//Restore scroll position
|
||||||
|
window.scrollTo(0, scrollY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're handling maxlength in JS, then having the maxlength attribute is annoying
|
// If we're handling maxlength in JS, then having the maxlength attribute is annoying
|
||||||
|
|
Loading…
Reference in New Issue