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. General Discussion
  3. Add my own JS

Add my own JS

Scheduled Pinned Locked Moved General Discussion
8 Posts 2 Posters 3.0k 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.
  • B
    B
    be-laud
    wrote on last edited by
    #1

    Hi everybody!
    I'm Audrey, freelancer art director. I choose Lay Theme for building my first website for a personal project (vertical garden shop) and I want to try & customize some things with the help of Js ans Css animations.

    Here is the situation :

    [http://codepen.io/be-laud/pen/pROVmz]

    I am trying to put this accordion in Lay Theme. HTML and CSS are integrated and both of them work, but I'm not very good in JS. I tried super hard to apply the Lay Theme documentation... but I still miss something!
    Could you please tell me how I should write it to make it compatible with Lay Theme ?

    Thanks a lot!

    Audrey

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

      Hey!
      Find out the type and id of the page where you want to have the accordion. Typically you can see that for example in the <body> tag, it has a class of id-* and type-*

      window.laytheme.on("newpageshown", function(layoutObj, type, obj){
      	if(type == "page" && obj.id == 1){
      		// Put all of your js, without document ready inside here
      	}
      });
      

      obviously type "page" and id 1 need to be replaced by the type and id of your page where you want the code executed.

      If you have problems making this work please post your code here :)

      1 Reply Last reply
      0
      • B
        B
        be-laud
        wrote on last edited by
        #3

        Hello Armin!

        Thank you for your answer, I've tried it, but I still don't understand.

        Here my code (compatible with every version of the Jquery library and it works on a simulator):

        window.laytheme.on("newpageshown", function(layoutObj, type, obj){
        if(type == "page" && obj.id == 109){

        	function close_accordion_section() {
                jQuery('.accordion .title').removeClass('active');
                jQuery('.accordion .section-content').slideUp(300).removeClass('open');
              
            }
        
            jQuery('.title').click(function(e) {
                // Grab current anchor value
                var currentAttrValue = jQuery(this).attr('href');
        
                if(jQuery(e.target).is('.active')) {
                    close_accordion_section();
                }else {
                    close_accordion_section();
        
                    // Add active class to section title
                    jQuery(this).addClass('active');
                    
                    // Open up the hidden content panel
                    jQuery('.accordion ' + currentAttrValue).slideDown(300).addClass('open');
        
                }
        
                e.preventDefault();
            });
        }
        

        });

        Thank you for your help :thinking:

        Audrey

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

          do you have a link to the website where you're trying to make this work please?

          1 Reply Last reply
          0
          • B
            B
            be-laud
            wrote on last edited by
            #5

            It's on this page, on the accordion:

            http://www.fusion-vegetale.fr/tutoriels/

            Thanks in advance!

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

              hey when I'm on your website I cannot find the javascript code that you posted above on the site.

              Are you sure you put <script></script> around your js?

              Custom js that I see, is only this:

              <script>(function() {

              })();</script>

              B 1 Reply Last reply
              0
              • arminunruhA arminunruh

                hey when I'm on your website I cannot find the javascript code that you posted above on the site.

                Are you sure you put <script></script> around your js?

                Custom js that I see, is only this:

                <script>(function() {

                })();</script>

                B
                B
                be-laud
                wrote on last edited by
                #7

                :scream: !!! Thank you so much!

                My js was in the "Custom JS" window of the page, where it's impossible to write <script></script>. I thought it was automatic...

                I've put it in the custom header, and IT WORKS!

                Merci Merci Merci

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

                  cool!! :)

                  hm i think maybe you had it in the custom css window

                  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