@@ -208,6 +208,35 @@ <h2>Cool</h2>
208208</ style >
209209
210210< script >
211+ const triggers = document . querySelectorAll ( '.cool > li' ) ;
212+ const background = document . querySelector ( '.dropdownBackground' ) ;
213+ const nav = document . querySelector ( '.top' ) ;
214+
215+ function handleEnter ( ) {
216+ this . classList . add ( 'trigger-enter' ) ;
217+ setTimeout ( ( ) => this . classList . contains ( 'trigger-enter' ) && this . classList . add ( 'trigger-enter-active' ) , 150 ) ;
218+ background . classList . add ( 'open' ) ;
219+
220+ const dropdown = this . querySelector ( '.dropdown' ) ;
221+
222+ const dropdownCoords = dropdown . getBoundingClientRect ( ) ;
223+ const navCoords = nav . getBoundingClientRect ( ) ;
224+ const coords = {
225+ height : dropdownCoords . height ,
226+ width : dropdownCoords . width ,
227+ top : dropdownCoords . top - navCoords . top ,
228+ left : dropdownCoords . left - navCoords . left
229+ } ;
230+ background . style . setProperty ( 'width' , `${ coords . width } px` ) ;
231+ background . style . setProperty ( 'height' , `${ coords . height } px` ) ;
232+ background . style . setProperty ( 'transform' , `translate(${ coords . left } px, ${ coords . top } px` ) ;
233+ }
234+ function handleLeave ( ) {
235+ this . classList . remove ( 'trigger-enter' , 'trigger-enter-active' ) ;
236+ background . classList . remove ( 'open' ) ;
237+ }
238+ triggers . forEach ( trigger => trigger . addEventListener ( 'mouseenter' , handleEnter ) ) ;
239+ triggers . forEach ( trigger => trigger . addEventListener ( 'mouseleave' , handleLeave ) ) ;
211240</ script >
212241
213242</ body >
0 commit comments