Replace your code with this one:
import { timeline } from 'wix-animations';
function toggleFoldStikyMenu(index) {
let $FoldStikyMenu = $w('#StickyNavBarMenu' + index);
let $FoldMenu = $w('#Menu' + index);
// Switch between menus
if ($FoldStikyMenu.collapsed, $FoldMenu.expand) {
$FoldStikyMenu.expand();
$FoldMenu.collapse();
NavbarAnimationExpand(index)
} else {
$FoldStikyMenu.collapse();
$FoldMenu.expand();
NavbarAnimationCollapsed(index)
MenuAnimation(index)
}
// Close the other menus
[1, 2, 3]
.filter(idx => idx !== index)
.forEach(idx => {
$w('#StickyNavBarMenu' + idx).collapse();
$w('#Menu' + idx).expand();
NavbarAnimationCollapsed(index)
MenuAnimation(index)
})
$w('#StickyNavBarMenu' + index).onMouseOut(() => {
$w('#StickyNavBarMenu' + index).collapse();
$w('#Menu' + index).expand();
NavbarAnimationCollapsed(index)
})
}
function MenuAnimation(index) {
const target = $w('#Menu' + index);
timeline()
.add(target, { y: 0, x: 80, scale: 1, duration: 600, easing: 'easeOutElastic' })
.play();
}
function NavbarAnimationExpand(index) {
const target = $w('#StickyNavBarMenu' + index);
timeline()
.add(target, { y: 0, x: 140, scale: 1, duration: 600, easing: 'easeOutElastic' })
.play();
}
function NavbarAnimationCollapsed(index) {
const target1 = $w('#StickyNavBarMenu' + index);
const target = $w('#Menu' + index);
const reset = { y: 0, x: 0, scale: 1, duration: 600, easing: 'easeOutElastic' };
timeline()
.add(target1, reset)
.add(target, reset)
.play();
}
export function Menu1_mouseIn(event) {
toggleFoldStikyMenu(1);
}
export function Menu2_mouseIn(event) {
toggleFoldStikyMenu(2);
}
export function Menu3_mouseIn(event) {
toggleFoldStikyMenu(3);
}
In the new function update, do not use this part of the code anymore:
export function StickyNavBarMenu1_mouseOut(event) {
toggleFoldStikyMenu(1);
}
export function StickyNavBarMenu2_mouseOut(event) {
toggleFoldStikyMenu(2);
}
export function StickyNavBarMenu3_mouseOut(event) {
toggleFoldStikyMenu(3);
}
The container box shrinkage is already built into the code. This snippet here will be responsible for shrinking the container box when the mouse leaves it. This snippet is already integrated into the code.
$w('#StickyNavBarMenu' + index).onMouseOut(() => {
$w('#StickyNavBarMenu' + index).collapse();
$w('#Menu' + index).expand();
NavbarAnimationCollapsed(index)
})
These are the settings for the buttons and the container boxes:


You have not indicated what should happen when the function is called.
export function StickyNavBarMenu1_mouseOut_2(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
}
example:
export function StickyNavBarMenu1_mouseOut(event) {
toggleFoldStikyMenu(1);
}
You can delete that part, too:
**
* Adds an event handler that runs when the mouse pointer is moved
onto the element.
You can also [define an event handler using the Properties and Events panel](https://support.wix.com/en/article/velo-reacting-to-user-actions-using-events).
[Read more](https://www.wix.com/corvid/reference/$w.Element.html#onMouseIn)
* @param {$w.MouseEvent} event
*/
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here: