Shopify themes, liquid, logos, and UX
i have added the hover effect on the header but the drop-down menu item leaves before i can click on them so it's like showing sub-menu on hover but it couldn't get open.store url
let items = document .querySelector(".header__inline-menu") .querySelectorAll("details"); for (const item of items) { // Open the dropdown on hover item.addEventListener("mouseover", () => { item.setAttribute("open", true); }); // Close the dropdown when mouse leaves the whole item (dropdown box) item.addEventListener("mouseleave", () => { item.removeAttribute("open"); }); } "i have inserted this Js Script for hover effect"
Solved! Go to the solution
This is an accepted solution.
@odejia9587, change the code like this
let items = document.querySelectorAll(".header__inline-menu details");
items.forEach(item => {
item.addEventListener("mouseover", () => {
item.setAttribute("open", true);
item.querySelector("ul").addEventListener("mouseleave", () => {
item.removeAttribute("open");
});
item.addEventListener("mouseleave", () => {
item.removeAttribute("open");
});
});
});
And add this code before </body> tag in theme.liquid file
<style>
header-menu [open] summary:after {
content: "";
position: absolute;
height: 2em;
top: 3em;
left: -2em;
right: -2em;
}
</style>
B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.
B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.
B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.
BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now
Hi @odejia9587 ,
Try the below code please
let items = document
.querySelector(".header__inline-menu")
.querySelectorAll("details");
for (const item of items) {
item.addEventListener("mouseover", () => {
item.setAttribute("open", true);
});
item.addEventListener("mouseleave", (event) => {
const submenu = item.querySelector("ul");
if (!submenu || !submenu.contains(event.relatedTarget)) {
item.removeAttribute("open");
}
});
item.querySelector("ul").addEventListener("mouseover", () => {
item.setAttribute("open", true);
});
item.querySelector("ul").addEventListener("mouseleave", (event) => {
if (!item.contains(event.relatedTarget)) {
item.removeAttribute("open");
}
});
}
If my reply is helpful, kindly click like and mark it as an accepted solution.
Thanks!
@odejia9587, You can use this code to keep the submenu visible when the mouse leaves.
let items = document.querySelectorAll(".header__inline-menu details");
items.forEach(item => {
let closeTimeout;
item.addEventListener("mouseover", () => {
clearTimeout(closeTimeout);
item.setAttribute("open", true);
});
item.addEventListener("mouseleave", () => {
closeTimeout = setTimeout(() => {
item.removeAttribute("open");
}, 400);
});
item.querySelector("ul").addEventListener("mouseenter", () => {
clearTimeout(closeTimeout)
});
item.querySelector("ul").addEventListener("mouseleave", () => {
closeTimeout = setTimeout(() => {
item.removeAttribute("open");
}, 400);
});
});
B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.
B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.
B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.
BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now
i applied it but it working with a little bit of lag or delay
This is an accepted solution.
@odejia9587, change the code like this
let items = document.querySelectorAll(".header__inline-menu details");
items.forEach(item => {
item.addEventListener("mouseover", () => {
item.setAttribute("open", true);
item.querySelector("ul").addEventListener("mouseleave", () => {
item.removeAttribute("open");
});
item.addEventListener("mouseleave", () => {
item.removeAttribute("open");
});
});
});
And add this code before </body> tag in theme.liquid file
<style>
header-menu [open] summary:after {
content: "";
position: absolute;
height: 2em;
top: 3em;
left: -2em;
right: -2em;
}
</style>
B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.
B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.
B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.
BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now
Thank you so much for helping i have searched it for everywhere
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024