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

Add my own JS

Scheduled Pinned Locked Moved General Discussion
8 Posts 2 Posters 2.1k 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.
  • B Offline
    B Offline
    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 Offline
      arminunruhA Offline
      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 Offline
        B Offline
        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 Offline
          arminunruhA Offline
          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 Offline
            B Offline
            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 Offline
              arminunruhA Offline
              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 Offline
                B Offline
                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 Offline
                  arminunruhA Offline
                  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
                  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
                  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