Skip to content

Commit 5d238cd

Browse files
committed
Nav Dropdown Updates
1 parent 65850ae commit 5d238cd

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nav.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,37 @@ function handleTriggerHover(targetName) {
122122
currentTrigger = targetName;
123123
gsap.set($currentTarget, { autoAlpha: 1 });
124124

125-
const parentRect = $menuInner.parent()[0].getBoundingClientRect();
125+
// Reset x so we can measure the natural position
126+
gsap.set($menuInner, { left: '50%', xPercent: -50 });
127+
126128
const triggerRect = $currentTriggerEl[0].getBoundingClientRect();
127-
const menuWidth = $menuInner.outerWidth();
128129

129-
const triggerCenter = triggerRect.left + triggerRect.width / 2;
130-
const parentCenter = parentRect.left + parentRect.width / 2;
131-
let offsetFromCenter = triggerCenter - parentCenter;
130+
// Natural center = parentLeft + 50% of parentWidth (from CSS left: 50%)
131+
const parentRect = $menuInner.parent()[0].getBoundingClientRect();
132+
const menuNaturalCenter = parentRect.left + parentRect.width / 2;
133+
134+
// Use a fixed known width — read once on init or from first panel
135+
const menuWidth = $allTargets.first()[0].scrollWidth;
132136

133-
const finalLeft = parentRect.left + offsetFromCenter;
134-
const finalRight = finalLeft + menuWidth;
135137
const windowWidth = $(window).width();
136138
const edgePadding = 20;
137139

140+
const triggerCenter = triggerRect.left + triggerRect.width / 2;
141+
let offsetFromCenter = triggerCenter - menuNaturalCenter;
142+
143+
const finalLeft = menuNaturalCenter - menuWidth / 2 + offsetFromCenter;
144+
const finalRight = finalLeft + menuWidth;
145+
146+
console.log({
147+
menuWidth,
148+
menuNaturalCenter,
149+
triggerCenter,
150+
offsetFromCenter,
151+
finalLeft,
152+
finalRight,
153+
windowWidth,
154+
});
155+
138156
if (finalLeft < edgePadding) {
139157
offsetFromCenter += edgePadding - finalLeft;
140158
} else if (finalRight > windowWidth - edgePadding) {

0 commit comments

Comments
 (0)