A dropdown navigation menu that follows the mouse along each list item in the top. The size of the background of the dropdown adjusts to the size of the content menu. Tutorial from Wes Bos Javascript30 Youtube series.
Note: to open web links in a new window use: ctrl+click on link
Open index.html in browser. If any code is changed the browser needs to be refreshed.
π» Code Examples
part of function handleEnter() to get dropdown and nav coords and use them in const coords
constdropdown=this.querySelector('.dropdown');//different dropdown under each list itemconstdropdownCoords=dropdown.getBoundingClientRect();//gets dimensions of dropdown rectconstnavCoords=nav.getBoundingClientRect();//in case header added etc that would push the whole menu position downconstcoords={height: dropdownCoords.height,width: dropdownCoords.width,top: dropdownCoords.top-navCoords.top,left: dropdownCoords.left-navCoords.left};
π Features
Uses the element.getBoundingClientRect() method that returns the size of an element and its position relative to the viewport; properties left, top, right, bottom, x, y, width, height.