Because I COPY below the code to global.js ,on mobile drop menu i can see all the collections,but can’t open the Have Multistage Menu collections,Can help me?
// Add this code make menu appears on hover
summary.addEventListener(‘mouseover’, (event) => {
const menuDetails = event.currentTarget.closest(‘details’);
const menuListContainer = menuDetails.closest(‘ul’)
event.currentTarget.setAttribute(‘aria-expanded’, ‘true’);
menuDetails.setAttribute(‘open’, ‘true’);
menuListContainer.addEventListener(‘mouseleave’, () => {
menuDetails.removeAttribute(‘open’);
summary.setAttribute(‘aria-expanded’, ‘false’);
});
menuDetails.addEventListener(“mouseleave”, () => {
menuDetails.removeAttribute(“open”);
summary.setAttribute(‘aria-expanded’, ‘false’);
});
});
Hello, @dongfuCamera
The code you provided appears to be attempting to make a menu open on hover for mobile devices. However, it seems to be missing some elements that are required for the correct functioning of a dropdown menu.
Here are some things to consider and modify in your code
HTML Structure: Ensure that your HTML structure is correctly set up with the
and elements for your menu items. The element should contain the menu content, and the element should be the trigger for opening and closing the menu.
Event Handling: The event listener code you provided seems to be missing the part that toggles the menu open and close on hover. You should add code to toggle the open attribute of the
element based on hover events.
Here’s an example of how you can modify your code
const summaryElements = document.querySelectorAll('summary');
summaryElements.forEach((summary) => {
summary.addEventListener('mouseover', () => {
const menuDetails = summary.parentElement; // Get the parent
- This code adds event listeners to all <summary> elements, opens the associated <details> element on hover, and closes it on mouseout.
- **Aria Roles and Attributes**: Ensure that you've correctly set ARIA roles and attributes for accessibility. Make sure your <summary> elements have role="button" and aria-expanded attributes to indicate the state of the dropdown menu.
```markup
Remember to replace ‘Menu Item’ and ‘Menu content goes here’ with your actual menu item text and content.
1 Like
still not working on mobile drop menu