Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. close overlay by pressing burger again mobile

close overlay by pressing burger again mobile

Scheduled Pinned Locked Moved General Discussion
5 Posts 2 Posters 91 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jasonk
    wrote on last edited by
    #1

    Hello!

    I am currently working on a diy mobile-menu. Why?: I wanted to have a burger menu that gives me more freedom of what to place where, collaps rows etc.
    Maybe there is another function for this? jasonkittner.com

    Plan is to use the overlay function of a page and use the burger. I managed that the burger swaps to an X the second you press it. But I cannot figure out how to address the now X to close the menu. I tried to use the close button function of the overlay but didn't like that it doesn't replace the burger. this is the code i have right now:

    document.addEventListener("DOMContentLoaded", function() {
        var burgerIcon = document.querySelector('.overlay-burger.custom-overlay-burger.burger-overlay-id-73 img');
        var originalSrc = burgerIcon.src; // og burger icon
        var toggleSrc = 'https://www.jasonkittner.com/wp-content/uploads/2024/10/Burger2.png'; // url of x icon
    
        burgerIcon.addEventListener('click', function() {
            burgerIcon.src = (burgerIcon.src.includes(originalSrc)) ? toggleSrc : originalSrc;
        });
    });
    
    

    I tried this to make the burger close the overlay:

    <script>
    jQuery(document).on('click', '.overlay-burger.custom-overlay-burger.burger-overlay-id-73', function(){
        jQuery('.lay-overlay .overlay-close.custom-overlay-close-icon').click();
    });
    </script>
    

    Happy to hear from you!

    1 Reply Last reply
    0
    • arminunruhA Offline
      arminunruhA Offline
      arminunruh
      Global Moderator
      wrote on last edited by
      #2

      nice website!

      if your button has a class of "overlay-close"

      (without the "")
      then clicking it should close a page overlay

      1 Reply Last reply
      0
      • arminunruhA Offline
        arminunruhA Offline
        arminunruh
        Global Moderator
        wrote on last edited by
        #3

        so after opening the overlay you can add this class i guess!

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jasonk
          wrote on last edited by
          #4

          Hi Armin! I appreciate you like the website and thanks for the reply. Just found time to try and fix the error, but it just wont work.

          this is the code i came up with now:

          document.addEventListener("DOMContentLoaded", function() {
              var burgerContainer = document.querySelector('.overlay-burger.custom-overlay-burger.burger-overlay-id-73');
              var burgerIcon = burgerContainer.querySelector('img');
              var originalSrc = burgerIcon.src; // Original burger icon
              var toggleSrc = 'https://www.jasonkittner.com/wp-content/uploads/2024/10/Burger2.png'; // URL of the 'X' icon
          
              // Image toggle functionality and adding classes to the container
              burgerContainer.addEventListener('click', function() {
                  if (burgerIcon.src.includes(originalSrc)) {
                      burgerIcon.src = toggleSrc;
                      burgerContainer.classList.add('overlay-close'); // Add the classes to the container
                  } else {
                      burgerIcon.src = originalSrc;
                      burgerContainer.classList.remove('overlay-close'); // Remove the classes from the container
                  }
              });
          });
          
          1 Reply Last reply
          0
          • arminunruhA Offline
            arminunruhA Offline
            arminunruh
            Global Moderator
            wrote on last edited by
            #5

            hey jason really nice website

            using your javascript, the click event doesn't even get triggered for me
            but if i bind the click event so it does get triggered by using:

            jQuery(document).on('click', '.burger-overlay-id-3043', function(event){
            })
            

            somehow the overlay doesnt even show up

            how about you just use the normal X close icon without replacing anything
            Screenshot 2024-11-17 at 09.40.52.png

            i cant make it work the way you want unfortunately :/

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            I also code custom websites or custom Lay features.
            šŸ’æ Email me here: šŸ’æ
            info@laytheme.com

            Before you post:
            1. When using a WordPress Cache plugin, disable it or clear your cache.
            2. Update Lay Theme and all Lay Theme Addons
            3. Disable all Plugins
            4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

            This often solves issues you might run into

            When you post:
            1. Post a link to where the problem is
            2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
            3. If the problem is difficult to explain, post screenshots / link to a video to explain it
            Online Users
            A
            alasdair17
            M
            MATTOFIRE
            M
            matejmoravec
            Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
            laytheme.com
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Recent
            • Tags
            • Popular
            • Users
            • Search