mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Add correct-scroll-position
behavior transformer (#31486)
Add `correct-scroll-position` behavior transformer
This commit is contained in:
@ -49,17 +49,17 @@ function correctScrollPosition() {
|
||||
// This pushes the fixed element offscreen
|
||||
// Here we detect when the composer's top position is above the window's
|
||||
// current scroll offset and correct it
|
||||
later(() => {
|
||||
const el = document.querySelector("#reply-control");
|
||||
const rect = el.getBoundingClientRect();
|
||||
|
||||
if (rect.top < -1) {
|
||||
const scrollAmount = window.scrollY + rect.top;
|
||||
|
||||
window.scrollTo({
|
||||
top: scrollAmount,
|
||||
behavior: "instant",
|
||||
});
|
||||
}
|
||||
}, 150);
|
||||
applyBehaviorTransformer("composer-position:correct-scroll-position", () => {
|
||||
later(() => {
|
||||
const el = document.querySelector("#reply-control");
|
||||
const rect = el.getBoundingClientRect();
|
||||
if (rect.top < -1) {
|
||||
const scrollAmount = window.scrollY + rect.top;
|
||||
window.scrollTo({
|
||||
top: scrollAmount,
|
||||
behavior: "instant",
|
||||
});
|
||||
}
|
||||
}, 150);
|
||||
});
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
export const BEHAVIOR_TRANSFORMERS = Object.freeze([
|
||||
// use only lowercase names
|
||||
"composer-position:correct-scroll-position",
|
||||
"composer-position:editor-touch-move",
|
||||
"discovery-topic-list-load-more",
|
||||
"full-page-search-load-more",
|
||||
|
Reference in New Issue
Block a user