How do i make it so the menu drops down when I hover the mouse over it instead of only when I click it?
hello @Caligirl917
Please provide website url and if your store is password protected then also provide password So I will check and provide a solution here.
https://chngsara.myshopify.com/
Thank you!
Hi Sara, I just posted a video tutorial on my Youtube channel that may be what you are looking for.
Steps
-
Open your site’s code editor
-
Open your site’s header.liquid file (should be located in the sections folder
-
On around line 500 you will see a liquid tag referring to sticky headers, after this line copy the following code (it’s a simple script that adds hover eventListeners to all menu items that create dropdowns)
<script>
let items = document.querySelector(".header__inline-menu").querySelectorAll("details");
console.log(items)
items.forEach(item => {
item.addEventListener("mouseover", () => {
item.setAttribute("open", true);
item.querySelector("ul").addEventListener("mouseleave", () => {
item.removeAttribute("open");
});
item.addEventListener("mouseleave", () => {
item.removeAttribute("open");
});
});
});
</script>
Copy
Hope this helps, let me know if you have any issues!
Worked perfectly! Thank you so much!!
Glad to help! Could you please mark it as an accepted solution?
Hello,
Is there a way I can have the submenus and their options displayed all at once (preferably in separate columns) while hovering over the main parent menu? So you wouldn’t have to hover over the submenus as well to see their options?
Thanks!
Thanks! @wmiz . Works like charm
Question about editing the source code, when Shopify does updates, does it override the code that we insert and we have to do it all over again later, or does our code remain intact and unchanged? Thanks.
Just dropping by for the solution thought I’d answer your question.
No, Shopify does not change amended code upon update to my knowledge. This would make a lot of businesses extremely unhappy, as most professional Shopify stores have custom code to some capacity. Hope this helps.
This solution not work with Dawn 2.0
Thank you so much. I’ve been trying to find this for my Sense theme fore the longest while now. You are a lifesaver.
Hi @wmiz ,
first of all thank you for the code as well as for your videos on YouTube. I tried it out and it worked perfectly for me, the only thing is, that I have two submenu points under my menu. Now with the help of your code I can hover over the menu items and also select my submenu pages but when I move my mouse away from the first item, the entire menu closes and I can’t select my 2nd sub-item at all or move my mouse to the 2nd sub-item. Do you also have this problem or is there any known solution for something like this?
I hope you can help me.
Thank you in advance
Maollin
Not Working on Dawn 2.0
This worked beautifully!
Thank you.
In the new 5.0 this opens the megamenu, but when you try to move the mouse down to the menu it closes. Any idea?
For the recent Dawn updates, you can use the following code. It’s a bit long and not the best formatted, but it works alright.
First, you need to find the .mega-menu__content container in your header file and add the following events:
onmouseover="jackMousein(this)" onmouseleave="jackMouseout(this)"
You can add the following JS at the end of the header file(before the schema content).
You can also reach out to me for further consultation on the same.
Hi,
can someone explain me how to do it for the new refresh theme?
Thank you so much!