Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Brite
  • 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. Bug Reports
  3. Accordion // Jqueri loading issues

Accordion // Jqueri loading issues

Scheduled Pinned Locked Moved Bug Reports
8 Posts 2 Posters 790 Views 2 Watching
  • 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.
  • Sarah DellingS
    Sarah DellingS
    Sarah Delling
    wrote on last edited by
    #1

    I use an accordion on this website for the services description, here:
    https://zahnarztpraxis-alteglofsheim.de/leistungen/

    I have inserted it as custom code. It is inserted as follows:

    1. html-Element on my specific page "services" in pages:

    <div class="custom-accordion">
    <div class="accordion-item">
    <button class="accordion-title">XXX</button>
    <div class="accordion-content">
    <p>XXX</p>
    </div>
    </div>

    2. CSS in Lay Theme Options Custom Code:

    .custom-accordion {
    max-width: 800px;
    margin: 0 auto;
    }

    .accordion-item {
    border-bottom: 1px solid #ccc;
    }

    .accordion-title {
    width: 100%;
    text-align: left;
    padding: 15px;
    background: none;
    border: none;
    font-size: 40px;
    font-family: 'Belwe Std light';
    cursor: pointer;
    transition: all 0.3s ease;
    color: #e4e1da
    }

    .accordion-title:hover {
    color: #000;
    }

    .accordion-content {
    display: none;
    overflow: hidden;
    opacity: 1;
    max-height: none;
    color: #000;
    padding: 10px 15px;
    animation: fadeIn 0.3s ease-in-out;
    font-size: 16px;
    color: #000;
    line-height: 1.5;
    font-family: 'PTMono-Regular';
    text-align: left;
    }

    3. HTML-Code footer in Lay Theme Options Custom Code

    <script>

    jQuery(document).ready(function($) {
    $(".accordion-title").off("click").on("click", function() {
    var content = $(this).next(".accordion-content");

        if (content.is(":visible")) {
            content.slideUp(300).css("display", "none");
            $(this).removeClass("active");
        } else {
            $(".accordion-content").slideUp(300).css("display", "none"); // Alle schließen
            $(".accordion-title").removeClass("active");
    
            content.css("display", "block").hide().slideDown(300); // Sichtbar machen
            $(this).addClass("active");
        }
    });
    

    });

    </script>

    NOW: the problem :)

    The accordion is showing, working super fine, BUT only if I do a hard refresh loading on the site. The accordion doesn´t work/open when the page is loading for the first time. So I feel like the jQuery needs the hard refresh to work.

    Is there any way to fix this issue?

    Thanks so much for advices!

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

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

      use

      window.laytheme.on('newpageshown', function(){
      
      })
      

      instead of jquery document ready

      content is loaded in through ajax,
      jquery document ready only triggers on a hard refresh / load though

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

        nicely done the website! <3

        1 Reply Last reply
        0
        • Sarah DellingS
          Sarah DellingS
          Sarah Delling
          wrote on last edited by
          #4

          Thanks so much! 🤗 Looking foward for many more to come.

          And sorry, I have to ask again – I´m new to the game trying to learn.

          I inserted it like this now and think I made sth wrong, because now the pictures on the whole website are not loading.

          <script>

          window.laytheme.on('newpageshown', function(){
          $(".accordion-title").off("click").on("click", function() {
          var content = $(this).next(".accordion-content");

          if (content.is(":visible")) {
              content.slideUp(300).css("display", "none");
              $(this).removeClass("active");
          } else {
              $(".accordion-content").slideUp(300).css("display", "none"); // Alle schließen
              $(".accordion-title").removeClass("active");
          
              content.css("display", "block").hide().slideDown(300); // Sichtbar machen
              $(this).addClass("active");
          }
          

          });
          });

          </script>

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

            i think u need to use jQuery instead of $

            <script>
            window.laytheme.on('newpageshown', function(){
                jQuery(".accordion-title").off("click").on("click", function() {
                    var content = jQuery(this).next(".accordion-content");
            
                    if (content.is(":visible")) {
                        content.slideUp(300).css("display", "none");
                        jQuery(this).removeClass("active");
                    } else {
                        jQuery(".accordion-content").slideUp(300).css("display", "none"); // Alle schließen
                        jQuery(".accordion-title").removeClass("active");
            
                        content.css("display", "block").hide().slideDown(300); // Sichtbar machen
                        jQuery(this).addClass("active");
                    }
                });
            });
            </script>
            
            1 Reply Last reply
            0
            • arminunruhA
              arminunruhA
              arminunruh
              Global Moderator
              wrote on last edited by
              #6

              actually i notice now all youre doing is binding a click event, so you can instead just do it like this:

              <script>
              jQuery(document).on('click', '.accordion-title', function() {
                  var content = jQuery(this).next(".accordion-content");
              
                  if (content.is(":visible")) {
                      content.slideUp(300).css("display", "none");
                      jQuery(this).removeClass("active");
                  } else {
                      jQuery(".accordion-content").slideUp(300).css("display", "none"); // Alle schließen
                      jQuery(".accordion-title").removeClass("active");
              
                      content.css("display", "block").hide().slideDown(300); // Sichtbar machen
                      jQuery(this).addClass("active");
                  }
              });
              </script>
              

              as you can read here:
              https://laytheme.com/documentation/custom-javascript.html#binding-click-events

              please read the docs ^^

              1 Reply Last reply
              0
              • Sarah DellingS
                Sarah DellingS
                Sarah Delling
                wrote on last edited by
                #7

                works! beyond happy now – thanks :) I´ll do.

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

                  i think it doesnt work. when i click to a different page and then go back to that page, the accordion doesnt open

                  1 Reply Last reply
                  0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  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