Refresh Theme - Overlay menu with js only work on mobile OR desktop, never on both

Hi

I am trying to get an overlay menu effect on my site using JS, but it only works on either the mobile or desktop. Never on both simultanously. I am editing the code in the custom liquid spaces.

I have tried to strip down the code to ONLY the code for the menu, to make it simple but no success. I have tried to give the menu different names for mobile and desktop, to minimize the risk for conflict but that doesnt seem to matter at all, still only works on one or the other, not both.

Right now it works on the desktop view, while the menu-button on the mobile-view render nothing.

My site

Can it be a bug in the theme? In that case, how do i contact the developers? If not, what am i doing wrong?

I use the theme Refresh 15.1.0

Hi @skurt23 ,

here’s how you can handle your overlay menu to ensure it works both on desktop and mobile views.

Ensure Correct CSS with Media Queries:

/* Desktop-specific styles */
@media (min-width: 750px) {
  .overlay-menu {
    display: none; /* Start with hidden */
  }
  .menu-open {
    display: block; /* Show the overlay when menu is open */
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 1000;
  }
}

/* Mobile-specific styles */
@media (max-width: 749px) {
  .overlay-menu {
    display: none; /* Start hidden on mobile */
  }
  .menu-open {
    display: block; /* Show menu when open on mobile */
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 1000;
  }
}

JavaScript to Handle Both Views:

document.addEventListener("DOMContentLoaded", function () {
  const menuButtonDesktop = document.querySelector('.menu-button-desktop');
  const menuButtonMobile = document.querySelector('.menu-button-mobile');
  const overlayMenu = document.querySelector('.overlay-menu');

  function toggleMenu() {
    overlayMenu.classList.toggle('menu-open');
  }

  // Desktop menu button listener
  if (menuButtonDesktop) {
    menuButtonDesktop.addEventListener('click', function () {
      toggleMenu();
    });
  }

  // Mobile menu button listener
  if (menuButtonMobile) {
    menuButtonMobile.addEventListener('click', function () {
      toggleMenu();
    });
  }
});

Verify with Refresh Theme Customizations:

document.addEventListener("DOMContentLoaded", function () {
  const menuButton = document.querySelector('.menu-button'); // Single button for both
  const overlayMenu = document.querySelector('.overlay-menu');

  function toggleMenu() {
    overlayMenu.classList.toggle('menu-open');
  }

  // Event listener for both mobile and desktop menus
  if (menuButton) {
    menuButton.addEventListener('click', function () {
      toggleMenu();
    });
  }
});

Let me know if this resolves the issue

Hi @skurt23 ,

I hope you’re doing well!

I have checked the theme console, and noticed that the JavaScript display the menu for both desktop and mobile is breaking due to the jQuery script not being loaded. You can see the console error in the screenshot below.


integrated to

Hi and thanks for your quick response!

The CSS part i get, but i am pretty new on javascript.

JavaScript to Handle Both Views:

where do i put this code?

Verify with Refresh Theme Customizations:

what do you mean by this?

Im sorry if my questions seem stupid, again i am very new on javascript :smiley:

Hi and thanks for your answer!

Okay so if i understand it right, its some kind of conflict with the javascript? That is the feeling ive been having but i dont really know if it is a development-bug or just me who isnt applying the scripts correctly?

Sorry, very new on javascripts :smiley:

Hi again

This is my custom CSS for the desktop view:

@media screen and (max-width: 751px) {
   {
    display: none !important;
  }
}

And the rest of the code added in the custom liquid for the desktop view:


[

![KI3.png|2480x1750](upload://zyM6cZIBUFcQ9PTibtJkzzF051n.png)
](https://1bfba6-ca.myshopify.com/)

  ×
  

    [# OM KRIMINFO](https://1bfba6-ca.myshopify.com/pages/om-kriminfo)
    [# JURIDISK HJÄLP](https://1bfba6-ca.myshopify.com/collections/frontpage)
    [# VANLIGA FRÅGOR](https://1bfba6-ca.myshopify.com/pages/vanliga-fragor)
    [# KONTAKT](https://1bfba6-ca.myshopify.com/pages/kontakt)
  

☰ 

[

![intagen.png|1250x1250](upload://b361z40k44SWoRsvQcPLZTKI1x9.png)

#### INTAGEN
](https://1bfba6-ca.myshopify.com/pages/intagen)

  

[

#### ANHÖRIG
](https://1bfba6-ca.myshopify.com/pages/anhorig)

 
[

![advokat.png|1250x1250](upload://d7Hn3Nz9pkN8THXu2OzngLfWP2v.png)

#### ADVOKAT
](https://1bfba6-ca.myshopify.com/pages/advokat)

    

{% render 'header-search', input_id: 'Search-In-Modal' %}

   

#### 
  - [OM KRIMINFO](https://1bfba6-ca.myshopify.com/pages/om-kriminfo) 

  - [JURIDISK HJÄLP](https://1bfba6-ca.myshopify.com/collections/frontpage) 

 - [VANLIGA FRÅGOR](https://1bfba6-ca.myshopify.com/pages/vanliga-fragor) 

 - [KONTAKT](https://1bfba6-ca.myshopify.com/pages/kontakt)

This is my custom css for the mobile view:

@media screen and (min-width: 750px) {
   {
    display: none !important;
  }
}

And the rest of the code added in the custom liquid for the mobile view:


[

![KRIMINFOLONG.png|1123x400](upload://xEG3wQU7t1VjAxGcwnQ6OSDElY1.png)
](https://1bfba6-ca.myshopify.com/)

  ×
  

    [# OM KRIMINFO](https://1bfba6-ca.myshopify.com/pages/om-kriminfo)
    [# JURIDISK HJÄLP](https://1bfba6-ca.myshopify.com/collections/frontpage)
    [# VANLIGA FRÅGOR](https://1bfba6-ca.myshopify.com/pages/vanliga-fragor)
    [# KONTAKT](https://1bfba6-ca.myshopify.com/pages/kontakt)
  

☰ 

    

{% render 'header-search', input_id: 'Search-In-Modal' %}

   

I also added a screenshot of the console after ive clicked on the overlay-menu-button: