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. Accordion Bug

Accordion Bug

Scheduled Pinned Locked Moved General Discussion
40 Posts 12 Posters 2.3k 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.
  • RichardR Offline
    RichardR Offline
    Richard
    Global Moderator
    wrote on last edited by
    #9

    Dear @Brant

    I have used the example you provided:
    https://www.w3schools.com/howto/howto_js_accordion.asp

    & this works for me, Did you remember to wrap your Javascript in a "Newpage Event"?

    https://laytheme.com/documentation.html#custom-javascript

    Custom CSS:

    /* Style the buttons that are used to open and close the accordion panel */
    .accordion {
      background-color: #eee;
      color: #444;
      cursor: pointer;
      padding: 18px;
      width: 100%;
      text-align: left;
      border: none;
      outline: none;
      transition: 0.4s;
    }
    
    /* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
    .active, .accordion:hover {
      background-color: #ccc;
    }
    
    /* Style the accordion panel. Note: hidden by default */
    .panel {
      padding: 0 18px;
      background-color: white;
      max-height: 0;
      overflow: hidden;
      transition: max-height 0.2s ease-out;
    }
    

    Custom HTML:

    <button class="accordion">Section 1</button>
    <div class="panel">
      <p>Lorem ipsum...</p>
    </div>
    
    <button class="accordion">Section 2</button>
    <div class="panel">
      <p>Lorem ipsum...</p>
    </div>
    
    <button class="accordion">Section 3</button>
    <div class="panel">
      <p>Lorem ipsum...</p>
    </div>
    

    Custom JS - Note how the script in wrapped in a Newpage Event :)

    <script>
    window.laytheme.on("newpageshown", function(layoutObj, type, obj){
    	if(type == "category" && obj.id == 1){
    		
    		var acc = document.getElementsByClassName("accordion");
            var i;
    
            for (i = 0; i < acc.length; i++) {
              acc[i].addEventListener("click", function() {
                this.classList.toggle("active");
                var panel = this.nextElementSibling;
                if (panel.style.maxHeight) {
                  panel.style.maxHeight = null;
                } else {
                  panel.style.maxHeight = panel.scrollHeight + "px";
                }
              });
            }
    		
    	}
    });
    </script>
    

    Hope this helps you @Brant

    Best Wishes
    Richard

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Brant
      wrote on last edited by
      #10

      Hi @Richard-Keith,
      i'ts kind of working now, thank you so much for helping me out!

      if you could just have a final quick look: unfortunately it only works when i put the html code in the section 'Custom HTML at bottom'. But not when i want to place it on the grid via 'add HTML'. How come that makes a difference?

      I Hope you can help me once more,
      All the best
      Norman

      1 Reply Last reply
      0
      • RichardR Offline
        RichardR Offline
        Richard
        Global Moderator
        wrote on last edited by
        #11

        Dear @Brant

        If you put the HTML part into "+more - HTML" it will be there but you need to remember to add some CSS to make it visible,
        Put some in "+More - HTML" and then send me the link & i can verify that it is indeed there :)

        Best
        Richard

        B 1 Reply Last reply
        0
        • RichardR Richard

          Dear @Brant

          If you put the HTML part into "+more - HTML" it will be there but you need to remember to add some CSS to make it visible,
          Put some in "+More - HTML" and then send me the link & i can verify that it is indeed there :)

          Best
          Richard

          B Offline
          B Offline
          Brant
          wrote on last edited by Brant
          #12

          hi @Richard-Keith,
          thanks for your quick response!

          so what I did now is also added the css into the "+more-HTML'-part and put it into a <style></style>. the accordion was actually already visible before, but unlike the html I placed in the 'Custom HTML at bottom', it is not functional.

          I now put two accordions on the site: www.bodyandspace.de (one I added through "+more-HTML" and one I added to the 'Custom HTML at bottom' (this one is working).

          thanks

          Edit: It seems to work now, I have no idea how, but it works! thanks again richard!

          E 1 Reply Last reply
          0
          • RichardR Offline
            RichardR Offline
            Richard
            Global Moderator
            wrote on last edited by Richard
            #13

            Dear @Brant

            The Website looks Great! :)

            Good to see that it worked out and as always thank you for using Lay Theme.

            Best wishes
            Richard

            1 Reply Last reply
            0
            • B Brant

              hi @Richard-Keith,
              thanks for your quick response!

              so what I did now is also added the css into the "+more-HTML'-part and put it into a <style></style>. the accordion was actually already visible before, but unlike the html I placed in the 'Custom HTML at bottom', it is not functional.

              I now put two accordions on the site: www.bodyandspace.de (one I added through "+more-HTML" and one I added to the 'Custom HTML at bottom' (this one is working).

              thanks

              Edit: It seems to work now, I have no idea how, but it works! thanks again richard!

              E Offline
              E Offline
              egorkraft
              wrote on last edited by
              #14

              Hi @Brant I have exactly the same bug, accordion works ok when added at the 'Custom HTML at bottom' however the content isn't displayed if added through "+more-HTML".
              Can you please kindly specify what exactly did you put in <style></style>.
              Thanks.

              1 Reply Last reply
              0
              • RichardR Offline
                RichardR Offline
                Richard
                Global Moderator
                wrote on last edited by Richard
                #15

                Dear @egorkraft

                Could you post a link to your website and the Accordion in question, then i can take a better look :)

                Best
                Richard

                E 1 Reply Last reply
                0
                • RichardR Richard

                  Dear @egorkraft

                  Could you post a link to your website and the Accordion in question, then i can take a better look :)

                  Best
                  Richard

                  E Offline
                  E Offline
                  egorkraft
                  wrote on last edited by
                  #16

                  Hi @Richard-Keith. Thanks for a prompt reply.
                  You can find it here http://egorkraft.art/cas

                  Please don't mind the website being a mess atm :)

                  1 Reply Last reply
                  0
                  • RichardR Offline
                    RichardR Offline
                    Richard
                    Global Moderator
                    wrote on last edited by
                    #17

                    Dear @egorkraft

                    Apologies for the delay:
                    Im looking into it and we have a max-height of 0 ?
                    Screen Shot 2020-09-29 at 11.05.02 AM.png
                    The accordion gets the class "active' so it is triggering,

                    Could you post your HTML along with whatever CSS you are using?

                    If this doesn't work maybe you could send me a private message with your Login details and I can then take a proper look.

                    Let me know :)

                    Best
                    Richard

                    E 2 Replies Last reply
                    0
                    • RichardR Richard

                      Dear @egorkraft

                      Apologies for the delay:
                      Im looking into it and we have a max-height of 0 ?
                      Screen Shot 2020-09-29 at 11.05.02 AM.png
                      The accordion gets the class "active' so it is triggering,

                      Could you post your HTML along with whatever CSS you are using?

                      If this doesn't work maybe you could send me a private message with your Login details and I can then take a proper look.

                      Let me know :)

                      Best
                      Richard

                      E Offline
                      E Offline
                      egorkraft
                      wrote on last edited by egorkraft
                      #18

                      Hi @Richard-Keith,

                      I'm using just exactly what you have provided above in response to Brant in this chat:

                      Custom CSS (In Custom CSS & HTML panel)

                      /* Style the buttons that are used to open and close the accordion panel */
                      .accordion {
                        background-color: #ffffff;
                        color: #444;
                        cursor: pointer;
                        padding: 18px;
                        width: 100%;
                        text-align: left;
                        border: none;
                        outline: none;
                        transition: 0.4s;
                      }
                      
                      /* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
                      .active, .accordion:hover {
                        background-color: #ccc;
                        max-height: 100px;
                      }
                      
                      /* Style the accordion panel. Note: hidden by default */
                      .panel {
                        padding: 0 18px;
                        background-color: white;
                        max-height: 0;
                        overflow: hidden;
                        transition: max-height 0.2s ease-out;
                      }
                      

                      Custom <head> content

                      <script>
                      window.laytheme.on("newpageshown", function(layoutObj, type, obj){
                      	if(type == "project, page" && obj.id == 105, 81){
                      		
                      		var acc = document.getElementsByClassName("accordion");
                              var i;
                      
                              for (i = 0; i < acc.length; i++) {
                                acc[i].addEventListener("click", function() {
                                  this.classList.toggle("active");
                                  var panel = this.nextElementSibling;
                                  if (panel.style.maxHeight) {
                                    panel.style.maxHeight = null;
                                  } else {
                                    panel.style.maxHeight = panel.scrollHeight + "px";
                                  }
                                });
                              }
                      		
                      	}
                      });
                      </script>
                      

                      Custom HTML at bottom

                      <button class="accordion">Section 1</button>
                      <div class="panel">
                        <p>Lorem ipsum...</p>
                      </div>
                      
                      <button class="accordion">Section 2</button>
                      <div class="panel">
                        <p>Lorem ipsum...</p>
                      </div>
                      
                      <button class="accordion">Section 3</button>
                      <div class="panel">
                        <p>Lorem ipsum...</p>
                      </div>
                      

                      So as you can see custom HTML at bottom does work ok, however when I add just the same code to gridder via "+more - HTML" it gets the class "active' however max-height is not triggered. I tried adding various CSS properties of (max-height; overflow and display) to it but to no avail.

                      Thanks,

                      Best
                      Egor

                      1 Reply Last reply
                      0
                      • RichardR Richard

                        Dear @egorkraft

                        Apologies for the delay:
                        Im looking into it and we have a max-height of 0 ?
                        Screen Shot 2020-09-29 at 11.05.02 AM.png
                        The accordion gets the class "active' so it is triggering,

                        Could you post your HTML along with whatever CSS you are using?

                        If this doesn't work maybe you could send me a private message with your Login details and I can then take a proper look.

                        Let me know :)

                        Best
                        Richard

                        E Offline
                        E Offline
                        egorkraft
                        wrote on last edited by
                        #19

                        @Richard-Keith Hi again. I’m kindly pinging you to get back to me. Thanks in advance

                        1 Reply Last reply
                        0
                        • RichardR Offline
                          RichardR Offline
                          Richard
                          Global Moderator
                          wrote on last edited by Richard
                          #20

                          Dear @egorkraft

                          you must give your '.panel' in CSS a height. the class active is indeed being added to your accordion outer:

                          Screen Shot 2020-10-09 at 2.54.28 PM.png

                          But it cannot show anything because it is 0px high.

                          so something along the lines of

                          .panel {
                          
                            height:50px;
                            padding: 0 18px;
                            background-color: white;
                            max-height: 0;
                            overflow: hidden;
                            transition: max-height 0.2s ease-out;
                          }
                          

                          Let me know how this goes! :)
                          forgive me for the delay.

                          Best wishes, have a wonderful day & thank you for using Lay Theme

                          Sincerely
                          Richard

                          E 1 Reply Last reply
                          0
                          • RichardR Richard

                            Dear @egorkraft

                            you must give your '.panel' in CSS a height. the class active is indeed being added to your accordion outer:

                            Screen Shot 2020-10-09 at 2.54.28 PM.png

                            But it cannot show anything because it is 0px high.

                            so something along the lines of

                            .panel {
                            
                              height:50px;
                              padding: 0 18px;
                              background-color: white;
                              max-height: 0;
                              overflow: hidden;
                              transition: max-height 0.2s ease-out;
                            }
                            

                            Let me know how this goes! :)
                            forgive me for the delay.

                            Best wishes, have a wonderful day & thank you for using Lay Theme

                            Sincerely
                            Richard

                            E Offline
                            E Offline
                            egorkraft
                            wrote on last edited by
                            #21

                            @Richard-Keith Hi Richard, I tried what you suggested. but unfortunately it didn't do it.
                            I PM'ed my login details to you in case you could have a look some time soon ( :

                            1 Reply Last reply
                            0
                            • RichardR Offline
                              RichardR Offline
                              Richard
                              Global Moderator
                              wrote on last edited by
                              #22

                              Dear @egorkraft

                              Cool will take a look :)

                              Best
                              Richard

                              1 Reply Last reply
                              0
                              • FWF Offline
                                FWF Offline
                                FW
                                wrote on last edited by
                                #23

                                Any solution there? I do have the same problems as egorkraft!
                                Many thanks in advance.

                                1 Reply Last reply
                                0
                                • RichardR Offline
                                  RichardR Offline
                                  Richard
                                  Global Moderator
                                  wrote on last edited by
                                  #24

                                  Dear @FW

                                  Could you please link to your website with the Accordion on question, it could well be that the Accordion hasn't been given any dimensions yet with CSS - will have to see

                                  Best
                                  Richard

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    Suzanne
                                    wrote on last edited by
                                    #25

                                    Hi! I'm having the same problem here with the code provided by @Richard. The accordion is only working in right way if you use it in the bottom page html. If you use it inside the composer with "+ html" the accordion buttons appear but nothing happens when you click them.

                                    Adding a a height property in CSS to the panel doesn't seem to work either.

                                    1 Reply Last reply
                                    0
                                    • RichardR Offline
                                      RichardR Offline
                                      Richard
                                      Global Moderator
                                      wrote on last edited by Richard
                                      #26

                                      Dear @Suzanne

                                      Could you please post a link to your website with the Accordion?

                                      I can have a better look - Likely the Accordion contents need a height set with CSS.

                                      In @egorkraft 's case:

                                      you must give your '.panel' in CSS a height. the class active is indeed being added to your accordion outer:

                                      Screen Shot 2020-10-09 at 2.54.28 PM.png

                                      But it cannot show anything because it is 0px high.

                                      Set Height:

                                      .panel {
                                      
                                        height:50px;
                                        padding: 0 18px;
                                        background-color: white;
                                        max-height: 0;
                                        overflow: hidden;
                                        transition: max-height 0.2s ease-out;
                                      }
                                      

                                      Talk soon & have a wonderful day :)

                                      Sincerely
                                      Richard

                                      S 1 Reply Last reply
                                      0
                                      • RichardR Richard

                                        Dear @Suzanne

                                        Could you please post a link to your website with the Accordion?

                                        I can have a better look - Likely the Accordion contents need a height set with CSS.

                                        In @egorkraft 's case:

                                        you must give your '.panel' in CSS a height. the class active is indeed being added to your accordion outer:

                                        Screen Shot 2020-10-09 at 2.54.28 PM.png

                                        But it cannot show anything because it is 0px high.

                                        Set Height:

                                        .panel {
                                        
                                          height:50px;
                                          padding: 0 18px;
                                          background-color: white;
                                          max-height: 0;
                                          overflow: hidden;
                                          transition: max-height 0.2s ease-out;
                                        }
                                        

                                        Talk soon & have a wonderful day :)

                                        Sincerely
                                        Richard

                                        S Offline
                                        S Offline
                                        Suzanne
                                        wrote on last edited by
                                        #27

                                        Thanks @Richard, it's finally working! Besides adding a height property to "panel" I just had to add to the paragraph a class like "_Quote". Without a class the "<p>Lorem ipsum...</p>" wasn't working, so adding it makes it work even as in the bottom:

                                        <p class="_Quote">Lorem ipsum...</p>
                                        
                                        RichardR 1 Reply Last reply
                                        0
                                        • S Suzanne

                                          Thanks @Richard, it's finally working! Besides adding a height property to "panel" I just had to add to the paragraph a class like "_Quote". Without a class the "<p>Lorem ipsum...</p>" wasn't working, so adding it makes it work even as in the bottom:

                                          <p class="_Quote">Lorem ipsum...</p>
                                          
                                          RichardR Offline
                                          RichardR Offline
                                          Richard
                                          Global Moderator
                                          wrote on last edited by
                                          #28

                                          Dear @Suzanne

                                          Glad to hear it works, thank you for the update :)

                                          Best wishes
                                          Richard

                                          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
                                          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