Enable Dropdown Menu on Hover for Dawn Theme Heade

Solved

Enable Dropdown Menu on Hover for Dawn Theme Heade

Tadoori_Group
Tourist
4 0 1

Dawn Theme - How to get drop down menu list on hover instead of click?

Accepted Solution (1)

CodingFifty
Shopify Partner
914 136 164

This is an accepted solution.

Hi @Tadoori_Group,


Go to Online Store, then Theme, and select Edit Code.
Search for header.liquid file Add the provided code at the end of the file.

<script>
  let items = document.querySelector(".header__inline-menu").querySelectorAll("details");
let dropdownItems = document.querySelector(".header__submenu");
items.forEach(item => {
  item.addEventListener("mouseenter", () => {
    item.setAttribute("open", true);
    let ulElement = item.querySelector("ul");
    if (ulElement !== null) {
      ulElement.addEventListener("mouseleave", () => {
        item.removeAttribute("open");
      });
    }
  });
  item.addEventListener("focus", () => {
    item.setAttribute("open", true);
  });
  item.addEventListener("blur", () => {
    item.removeAttribute("open");
  });
  item.addEventListener("mouseenter", () => {
      item.setAttribute("open", "");
    });
    item.addEventListener("mouseleave", () => {
      item.removeAttribute("open");
    });
});
if (dropdownItems !== null) {
  dropdownItems.addEventListener("mouseleave", () => {
    items.forEach(item => {
      item.removeAttribute("open");
    });
  });
}
</script>

 

 

Coding Fifty || Shopify Partner
For any custom section queries, please visit: Fiverr Profile
Found my response useful? Like it and mark as Accepted Solution!
For additional discussions, reach out via: Email ID: codingfifty@gmail.com

View solution in original post

Replies 3 (3)

CodingFifty
Shopify Partner
914 136 164

This is an accepted solution.

Hi @Tadoori_Group,


Go to Online Store, then Theme, and select Edit Code.
Search for header.liquid file Add the provided code at the end of the file.

<script>
  let items = document.querySelector(".header__inline-menu").querySelectorAll("details");
let dropdownItems = document.querySelector(".header__submenu");
items.forEach(item => {
  item.addEventListener("mouseenter", () => {
    item.setAttribute("open", true);
    let ulElement = item.querySelector("ul");
    if (ulElement !== null) {
      ulElement.addEventListener("mouseleave", () => {
        item.removeAttribute("open");
      });
    }
  });
  item.addEventListener("focus", () => {
    item.setAttribute("open", true);
  });
  item.addEventListener("blur", () => {
    item.removeAttribute("open");
  });
  item.addEventListener("mouseenter", () => {
      item.setAttribute("open", "");
    });
    item.addEventListener("mouseleave", () => {
      item.removeAttribute("open");
    });
});
if (dropdownItems !== null) {
  dropdownItems.addEventListener("mouseleave", () => {
    items.forEach(item => {
      item.removeAttribute("open");
    });
  });
}
</script>

 

 

Coding Fifty || Shopify Partner
For any custom section queries, please visit: Fiverr Profile
Found my response useful? Like it and mark as Accepted Solution!
For additional discussions, reach out via: Email ID: codingfifty@gmail.com
Tadoori_Group
Tourist
4 0 1

underlin.PNG
Thanks! It worked!!
However, I want those underlines to be removed. Help with the code please.

kai23
Visitor
1 0 0

When trying to apply it I get this message 

  • Invalid JSON in tag 'schema'

What can I do to fix this?