How to change menu to appear on hover desktop

Solved

How to change menu to appear on hover desktop

Aleksander22
Explorer
164 0 57

Hi,

I need help with adding code including appearing menu on hover on desktop. Specifically mega menu. I would be grateful for help

Accepted Solutions (2)

BSSCommerce-B2B
Shopify Partner
1722 512 575

This is an accepted solution.

@Aleksander22 , follow these step

Step 1. Go to Admin -> Online store -> Theme > Edit code

Step 2. Find the file theme.liquid.

Step 3. Add this code above </body>

<script>
    document.addEventListener("DOMContentLoaded", (event) => {
        let items = document.querySelector(".header__inline-menu").querySelectorAll("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");
            });
        });
       });
    });
  </script>

Step 4: Find the file base.css and add this code to the end

header-menu [open] summary:after {
  content: "";
  position: absolute;
  height: 2em;
  top: 3em;
  left: -2em;
  right: -2em;
}

Hope it helps 😊

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

View solution in original post

BSSCommerce-B2B
Shopify Partner
1722 512 575

This is an accepted solution.

@Aleksander22, change the previous code in theme.liquid file like this

 

<script>
    document.addEventListener("DOMContentLoaded", (event) => {
        let items = document.querySelector(".header__inline-menu").querySelectorAll("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");
            });
        });
       });
      const listItems = document.querySelectorAll('.list-menu');
      const mainContent = document.getElementById('MainContent');
      
      listItems.forEach(item => {
        item.addEventListener('mouseenter', () => {
          mainContent.style.filter = 'blur(4px)';
        });
      
        item.addEventListener('mouseleave', () => {
          mainContent.style.filter = 'none';
        });
      });
    });
</script>

 

Result:

BSSCommerceB2B_0-1727018472257.png

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

View solution in original post

Replies 7 (7)

BSS-TekLabs
Shopify Partner
2350 701 826

Can you describe the problem you're having more clearly?

If our suggestions are useful, please let us know by giving it a like or marking it as a solution.


Salepify: Efficiently increase sales conversion with sale-driven features like auto add to cart, free gifts (free plan available)


Salemate: Boost your AVO with 2-layer offer, countdown upsell in your post purchase page


BSS Commerce - Full-service eCommerce Agency | Use Shopify for 1$ in the first month now
Aleksander22
Explorer
164 0 57

Thanks for your support  the other guy already help me

BSSCommerce-B2B
Shopify Partner
1722 512 575

This is an accepted solution.

@Aleksander22 , follow these step

Step 1. Go to Admin -> Online store -> Theme > Edit code

Step 2. Find the file theme.liquid.

Step 3. Add this code above </body>

<script>
    document.addEventListener("DOMContentLoaded", (event) => {
        let items = document.querySelector(".header__inline-menu").querySelectorAll("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");
            });
        });
       });
    });
  </script>

Step 4: Find the file base.css and add this code to the end

header-menu [open] summary:after {
  content: "";
  position: absolute;
  height: 2em;
  top: 3em;
  left: -2em;
  right: -2em;
}

Hope it helps 😊

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

Aleksander22
Explorer
164 0 57

And could you also help me with one thing. I have to add thing like when you open mega menu background is turning into blury. Like on this example

 

Aleksander22_0-1727018130016.png

 

 

 

 

 

BSSCommerce-B2B
Shopify Partner
1722 512 575

This is an accepted solution.

@Aleksander22, change the previous code in theme.liquid file like this

 

<script>
    document.addEventListener("DOMContentLoaded", (event) => {
        let items = document.querySelector(".header__inline-menu").querySelectorAll("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");
            });
        });
       });
      const listItems = document.querySelectorAll('.list-menu');
      const mainContent = document.getElementById('MainContent');
      
      listItems.forEach(item => {
        item.addEventListener('mouseenter', () => {
          mainContent.style.filter = 'blur(4px)';
        });
      
        item.addEventListener('mouseleave', () => {
          mainContent.style.filter = 'none';
        });
      });
    });
</script>

 

Result:

BSSCommerceB2B_0-1727018472257.png

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

Aleksander22
Explorer
164 0 57

And last thing my content move to the left and it was in center how can I solve that

 

BSSCommerce-B2B
Shopify Partner
1722 512 575

@Aleksander22, You mean this one ?

BSSCommerceB2B_0-1727018769473.png

 

If so you could add this code to end of base.css file

.mega-menu__list {
    display: flex!important;
    justify-content: center;
}
.mega-menu__list > li {
    width: 16.67%;
}

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