Tthe Belgrade offcanvas navigation still reserves space for the top bar even after the page is scrolled. This creates an empty gap at the top of the offcanvas panel.
Issue fork belgrade-3576769
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
velmir_taky commentedThe gap happens because
topandmargin-topon the offcanvas are always set tovar(--beo-region-top-bar-height), even when the top-bar has scrolled out of view.Added an
IntersectionObserverinmain.jsthat tracks the top-bar visibility and updates a new--beo-region-top-bar-offsetvariable —3.5remwhen visible,0pxwhen not. CSS uses it with fallback to--beo-region-top-bar-heightso nothing breaks without JS.Comment #5
majmunbog commented@velmir_taky Thanks for looking into this. I'm not sure, but maybe an adjustment to the padding would be a simpler approach?
In any case,
--beo-region-top-bar-offsetis not really the right name for the variable, we are offsetting the navigation region.Comment #6
velmir_taky commentedThanks @majmunbog for the review!
Renamed
--beo-region-top-bar-offsetto--beo-navigation-region-offsetas suggested.Regarding padding — the issue is the offcanvas position, not its inner spacing.
margin-toppushes the entire panel down, leaving a visible gap. Padding would only shift the content inside while the gap remains. The IntersectionObserver approach dynamically updates the offset based on top-bar visibility.Comment #7
sumi commentedTesting the MR and offcanvas panel is now jumping on scroll.
When the user scrolls with the off-canvas panel open, the panel abruptly shifts upward to occupy the space previously taken by the top bar. The repositioning is visible as a noticeable "jump" rather than a smooth transition. Same jump happens when we scroll back up to position where top bar is visible.
The off-canvas panel should adjust its position seamlessly when the top bar scrolls in and out of view, without a visible jump.
Comment #8
velmir_taky commentedThanks @sumi for testing and the clear report.
The jump was caused by the
IntersectionObserverwiththreshold: 0: it only fires when the last pixel of the top bar enters or leaves the viewport, so--beo-navigation-region-offsetflipped instantly betweenvar(--beo-region-top-bar-height)(3.5rem) and0px. That single 3.5rem step is the visible jump — both scrolling down and back up.Reworked the behavior to track the top bar continuously instead of as a binary state. On scroll (throttled with
requestAnimationFrame) it sets the offset to the height of the top bar still visible in the viewport:Because the offset now follows the top bar's position pixel-by-pixel, the navigation region slides up in lock-step with the top bar and settles at
0pxexactly when the bar is gone — no jump in either direction. The Bootstrapshow/hiddenhandlers are no longer needed: the panel opens with whatever offset the last scroll frame set, which is already correct.CSS/SCSS are unchanged — the
var(--beo-navigation-region-offset, var(--beo-region-top-bar-height))fallback still degrades gracefully without JS.Comment #9
sumi commentedTested the latest changes in the MR and there is no longer "jump" on scroll that we had previously but now when we scroll and off-canvas moves up to take space of the top bar on the bottom of the page we are left with a gap in same size as the top-bar for which off-canvas moved up.
Off-canvas should always be full height of the screen and we should not have a gap between the off-canvas and the bottom of the page.
Comment #10
velmir_taky commentedFixed. The panel now stays full height - the top-bar offset is applied as
paddingon the content instead ofmarginon the panel, so no gap at top or bottom. Also gave.region-top-bar position: relativeso it stays above the full-height panel. Tested across sizes + RTL.Comment #11
sumi commentedTested the latest changes on the MR and all is looking good.
Comment #12
majmunbog commentedAddressed a couple of issues:
margin-toprules from_navigation.scss(including the redundant.region-top-bar ~ &selector). Top drawer offset is now only viatopinmain-nav.scss.show.bs.offcanvasand detach onhidden.bs.offcanvas, with an immediate measure on open so the offset is correct when the top bar has already scrolled away.npm run buildand committed the updatedcss/components/main-nav.css.mapandcss/main.css.map(plus the compiledcss/main.csscleanup from the SCSS changes).Pushed in
09a3a82. Please re-check the pipeline and the offcanvas-top / open-after-scroll cases.Comment #13
sumi commentedTested the latest changes and all is good.
Comment #15
majmunbog commented