Lay Theme Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Search

    custom code for desktop menu only

    General Discussion
    2
    4
    375
    Loading More Posts
    • 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.
    • R
      robin last edited by robin

      Hi,
      I'm hiding the main menu of my website until the user starts scrolling. Here is the jquery:

      jQuery(window).scroll(function() {
          if (jQuery(window).scrollTop() > 120) {
              jQuery("nav.primary").fadeIn();
          }
          else {
              jQuery("nav.primary").fadeOut();
          }
          });
      

      however, I never want to hide the mobile menu. How can I prevent this to happen? I tried to check it these ways because these are changing in my inspector when I go from desktop to mobile layout:

      if (jQuery("body").hasClass( "lightbox-css-on" ))
      if (jQuery('nav.primary').css('max-height') == '566px')

      but this doesn't seem to work. Any help?

      Thanks !

      Robin

      1 Reply Last reply Reply Quote 0
      • mariusjopen
        mariusjopen Global Moderator last edited by

        Hi @robin

        I would go for this way:

        if ($(window).width() > 767) {
        // YOUR CODE HERE
        }
        

        Also have a look here:
        http://laytheme.com/documentation.html#custom-javascript

        Let me know if you got further.

        Best!

        Marius

        www.mariusjopen.world

        1 Reply Last reply Reply Quote 0
        • R
          robin last edited by

          Hi,

          thanks! It's almost perfect now. I still have one problematic situation when the user manually resizes the window under 767px wide because then the "Custom CSS for Desktop Version" is still loaded with the "display: none" property that I use on the menu so it is not visible when the page is loaded. I guess I could fix this with more javascript or maybe this should be implemented in the theme directly (loading the right custom css when user resizes the window)?

          Thanks for your time.
          Best,

          Robin

          1 Reply Last reply Reply Quote 0
          • mariusjopen
            mariusjopen Global Moderator last edited by

            Have a look here:

            <script>
              jQuery(function () {
                if (jQuery(window).width() > 600) {
                  // YOUR CODE HERE	
                }
            
                jQuery(window).on('resize', function () {
                  if (jQuery(window).width() > 600) {
                     // YOUR CODE HERE	
                  }
                });
            
                jQuery(window).on('resize', function () {
                  if (jQuery(window).width() <= 600) {
                    // YOUR DISABLING CODE HERE	
                  }
                });
              });
            
            </script>
            
            

            Maybe you need to adjust it with this:
            http://laytheme.com/documentation.html#custom-javascript

            But that should cover it.

            Best!

            Marius

            www.mariusjopen.world

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            Before you post

            Use the Search Feature. Maybe there is already a solution to your issue.

            1. Update Lay Theme and all Lay Theme Addons
            2. Disable all Plugins
            3. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code ", click "Save Changes"
            4. Now see if your problem solved itself
            5. Go here, see if your problem is listed here:
            Troubleshooting

            When you post:
            1. Post a link to where the problem is
            2. If the problem is difficult to explain, post screenshots / link to a video to explain it

            Thanks!

            Online Users

            K
            T
            A
            S

            Recent Topics

            • A

              Theme crashed - because of Polylang?

            • A

              can't change front page

            • M

              komische boxen auf der Website

            laytheme.com