@@ -57,15 +57,6 @@ export const initSkyNav = (navButton: HTMLButtonElement) => {
57
57
return ;
58
58
}
59
59
60
- // We need to keep track of the siblings after the menu,
61
- // because we will push them down for the animation
62
- const elementsToShift : HTMLElement [ ] = [ navWrapper ] ;
63
- let sibling : HTMLElement | null = navWrapper ;
64
- // eslint-disable-next-line no-unmodified-loop-condition
65
- while ( ( sibling = sibling . nextElementSibling as HTMLElement | null ) ) {
66
- elementsToShift . push ( sibling ) ;
67
- }
68
-
69
60
const duration = Number . parseFloat ( tokens . time . transition . slow . value ) ;
70
61
const transition = `transform ${ duration } s ${ tokens . ease . in_out . value } ` ;
71
62
clearTimeout ( timeoutId ) ;
@@ -74,34 +65,31 @@ export const initSkyNav = (navButton: HTMLButtonElement) => {
74
65
const heightDiff = menu . getBoundingClientRect ( ) . height ;
75
66
if ( isExpanded ) {
76
67
// Closing menu: slide the elements up before hiding the menu
77
- for ( const el of elementsToShift ) {
78
- el . style . transition = transition ;
79
- el . style . transform = `translateY(${ - heightDiff } px)` ;
80
- }
68
+ document . body . style . setProperty ( 'transition' , transition ) ;
69
+ document . body . style . setProperty (
70
+ 'transform' ,
71
+ `translateY(${ - heightDiff } px)`
72
+ ) ;
81
73
82
74
timeoutId = setTimeout ( ( ) => {
83
75
menu . hidden = true ;
84
- for ( const el of elementsToShift ) {
85
- el . style . transition = '' ;
86
- el . style . transform = '' ;
87
- }
76
+ document . body . style . removeProperty ( 'transition' ) ;
77
+ document . body . style . removeProperty ( 'transform' ) ;
88
78
} , duration * 1000 ) as any as number ;
89
79
} else {
90
80
// Opening menu: start the elements higher than their "resting position" and then slide them down
91
- for ( const el of elementsToShift )
92
- el . style . transform = `translateY(${ - heightDiff } px)` ;
81
+ document . body . style . setProperty (
82
+ 'transform' ,
83
+ `translateY(${ - heightDiff } px)`
84
+ ) ;
93
85
94
86
// Flush changes to the DOM
95
87
// eslint-disable-next-line @cloudfour/typescript-eslint/no-unused-expressions, mdx/no-unused-expressions
96
88
navWrapper . offsetWidth ;
97
- for ( const el of elementsToShift ) {
98
- el . style . transition = transition ;
99
- el . style . transform = '' ;
100
- }
89
+ document . body . style . setProperty ( 'transition' , transition ) ;
90
+ document . body . style . removeProperty ( 'transform' ) ;
101
91
timeoutId = setTimeout ( ( ) => {
102
- for ( const el of elementsToShift ) {
103
- el . style . transition = '' ;
104
- }
92
+ document . body . style . removeProperty ( 'transition' ) ;
105
93
} , duration * 1000 ) as any as number ;
106
94
}
107
95
} ;
0 commit comments