custom code for desktop menu only
-
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
-
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-javascriptLet me know if you got further.
Best!
Marius
-
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
-
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-javascriptBut that should cover it.
Best!
Marius
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