Shopify themes, liquid, logos, and UX
How do i make it so the menu drops down when I hover the mouse over it instead of only when I click it?
Solved! Go to the solution
This is an accepted solution.
Glad to help! Could you please mark it as an accepted solution?
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.
Please share your store URL!
Thanks!
Hi Sara, I just posted a video tutorial on my Youtube channel that may be what you are looking for.
Steps
1. Open your site's code editor
2. Open your site's header.liquid file (should be located in the sections folder
3. 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>
Hope this helps, let me know if you have any issues!
This is an accepted solution.
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!
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
Try this one. No javascript being use. Just HTML and css. Check the video for more info
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 @wmisback ,
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).
<script>
function jackMousein(x){
let nodd = x.parentElement;
nodd.setAttribute('megaopen', true)
}
function jackMouseout(x){
let nodd = x.parentElement;
nodd.removeAttribute('megaopen')
}
let items = document.querySelector(".header__inline-menu").querySelectorAll("details");
items.forEach(item => {
item.addEventListener("mouseover", () => {
item.setAttribute("open", true);
item.querySelector("ul").addEventListener("mouseleave", () => {
setTimeout(function(){
if(item.hasAttribute('megaopen')){
item.setAttribute("open", true);
}
else{
item.removeAttribute("open");
}
}, 500);
});
item.addEventListener("mouseleave", () => {
setTimeout(function(){
if(item.hasAttribute('megaopen')){
item.setAttribute("open", true);
}
else{
item.removeAttribute("open");
}
}, 100);
});
});
});
</script>
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!
User | RANK |
---|---|
221 | |
145 | |
63 | |
46 | |
45 |
Thanks to all Community members that participated in our inaugural 2 week AMA on the new E...
By Jacqui Mar 10, 2023Upskill and stand out with the new Shopify Foundations Certification program
By SarahF_Shopify Mar 6, 2023One of the key components to running a successful online business is having clear and co...
By Ollie Mar 6, 2023