Shopify themes, liquid, logos, and UX
Hello!
I am using the dawn theme and my URL is carcleansweden.se.
I recently changed so the menu options show while hovering. But now the submenu disappears too quickly when I try to move my mouse to select an option in the dropdown box:
This is what I changed in theme.liquid for the hovering effect: "
<script>
document.querySelectorAll('.header__menu-item.list-menu__item').forEach(item => {
item.addEventListener('mouseenter', () => {
item.parentElement.setAttribute('open', '');
});
item.addEventListener('mouseleave', () => {
item.parentElement.removeAttribute('open');
});
});
</script>
"
I would hugely appreciate the help!
Solved! Go to the solution
This is an accepted solution.
Try this code instead and check again
<script>
const inlineMenu = document.querySelector(".header__inline-menu");
const detailsItems = inlineMenu.querySelectorAll("details");
detailsItems.forEach(item => {
const ulElement = item.querySelector("ul");
item.addEventListener("mouseover", () => {
item.setAttribute("open", true);
ulElement.addEventListener("mouseleave", () => {
item.removeAttribute("open");
});
item.addEventListener("mouseleave", () => {
item.removeAttribute("open");
});
});
});
</script>
- Helpful? Like & Accept solution! - Support me? Buy me a coffee
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
Hi @CarCleanCC
You can try to update your code to this code and check again
<script>
document.querySelectorAll('.header__menu-item.list-menu__item').forEach(item => {
let timeout;
item.addEventListener('mouseenter', () => {
clearTimeout(timeout); // Clear any existing timeout
item.parentElement.setAttribute('open', '');
});
item.addEventListener('mouseleave', () => {
// Set a timeout to delay the removal of the open attribute
timeout = setTimeout(() => {
item.parentElement.removeAttribute('open');
}, 300); // Adjust the delay as needed (300ms here)
});
// Ensure the submenu remains open if the cursor is inside the submenu
const submenu = item.querySelector('.submenu-class'); // Replace '.submenu-class' with the actual class of your submenu
if (submenu) {
submenu.addEventListener('mouseenter', () => {
clearTimeout(timeout);
});
submenu.addEventListener('mouseleave', () => {
timeout = setTimeout(() => {
item.parentElement.removeAttribute('open');
}, 300);
});
}
});
</script>
- Helpful? Like & Accept solution! - Support me? Buy me a coffee
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
It seems to still disappear after a second. Is it possible to leave it there when I have my mouse over it?
Thank you for your help
Code updated
<script>
document.querySelectorAll('.header__menu-item.list-menu__item').forEach(item => {
let timeout;
// Function to open the menu
const openMenu = () => {
clearTimeout(timeout); // Clear any existing timeout
item.parentElement.setAttribute('open', '');
};
// Function to close the menu
const closeMenu = () => {
timeout = setTimeout(() => {
item.parentElement.removeAttribute('open');
}, 300); // Delay before closing (300ms)
};
// Add event listeners to the menu item
item.addEventListener('mouseenter', openMenu);
item.addEventListener('mouseleave', closeMenu);
// Add event listeners to the submenu
const submenu = item.querySelector('.header__submenu'); // Replace '.submenu-class' with your submenu class
if (submenu) {
submenu.addEventListener('mouseenter', openMenu);
submenu.addEventListener('mouseleave', closeMenu);
}
});
</script>
- Helpful? Like & Accept solution! - Support me? Buy me a coffee
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
Seems to still be a countdown. Is it possible for it to show at all times when my mouse Is hovering the submenu box?
Thank you
This is an accepted solution.
Try this code instead and check again
<script>
const inlineMenu = document.querySelector(".header__inline-menu");
const detailsItems = inlineMenu.querySelectorAll("details");
detailsItems.forEach(item => {
const ulElement = item.querySelector("ul");
item.addEventListener("mouseover", () => {
item.setAttribute("open", true);
ulElement.addEventListener("mouseleave", () => {
item.removeAttribute("open");
});
item.addEventListener("mouseleave", () => {
item.removeAttribute("open");
});
});
});
</script>
- Helpful? Like & Accept solution! - Support me? Buy me a coffee
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
Where to paste this code? means at what line and which position?
Please add that code before </body> in theme.liquid file in Sales channels > Online Store > Themes > click "..." in Current theme > Edit code.
- Helpful? Like & Accept solution! - Support me? Buy me a coffee
- Ryviu - Product Reviews & QA app: Collect customer reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025