From 5bcd53f2deb41ef1b67735d92b396d2906f33a0a Mon Sep 17 00:00:00 2001 From: dianeCdrPix Date: Wed, 4 Dec 2024 10:01:05 +0100 Subject: [PATCH] refactor(mon-pix): edit constant and create methode to calculate offset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Latzarus --- mon-pix/app/services/modulix-auto-scroll.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mon-pix/app/services/modulix-auto-scroll.js b/mon-pix/app/services/modulix-auto-scroll.js index 6f7d0ae1c5d..ca5095465da 100644 --- a/mon-pix/app/services/modulix-auto-scroll.js +++ b/mon-pix/app/services/modulix-auto-scroll.js @@ -4,11 +4,18 @@ import Service, { service } from '@ember/service'; export default class ModulixAutoScroll extends Service { @service modulixPreviewMode; - #SCROLL_OFFSET_PX = 70; + #DISTANCE_BETWEEN_GRAIN_AND_NAVBAR_PX = 70; @action setHTMLElementScrollOffsetCssProperty(htmlElement) { - htmlElement.style.setProperty('--scroll-offset', `${this.#SCROLL_OFFSET_PX}px`); + htmlElement.style.setProperty('--scroll-offset', `${this.#getScrollOffset()}px`); + } + + #getScrollOffset({ getNavbar } = { getNavbar: this.#getNavbar }) { + const navbarElement = getNavbar(); + const navbarHeight = navbarElement ? navbarElement.getBoundingClientRect().height : 0; + + return this.#DISTANCE_BETWEEN_GRAIN_AND_NAVBAR_PX + navbarHeight; } focusAndScroll(