Viewing 21 posts - 1 through 21 (of 21 total)
  • Author
    Posts
  • #1426504

    Hello Enfold Team,

    I would like my left sidebar menu to shrink just like a top menu can. Once I start to scroll, I want it to become smaller and turn into the burger menu icon. Is this doable?

    As always, thank you for your help.

    -James

    #1426505

    Hey James,

    Thank you for the inquiry.

    You can try this script to toggle the display of the default menu and burger menu on scroll.

    function av_custom_inline_script()
    {
        wp_add_inline_script( 'jquery', 
            "
        (function($) {
            $(document).ready(function () {
                if (window.innerWidth > 989) {
                    var burger = $('.html_header_sidebar #top div .av-burger-menu-main');
                    var menu = $('.responsive.html_header_sidebar #header .av-main-nav > li').not('.av-burger-menu-main, .av-active-burger-item');
                    $(window).scroll(function () {
                      if ($(this).scrollTop() > 200) {
                        burger.show();
                        menu.hide();
                      } else {
                        menu.show();
                        burger.hide();
                      }
                    });
                } 
              });
        })(jQuery);
        "
        );
    }
    add_action( 'wp_enqueue_scripts', 'av_custom_inline_script' );

    Best regards,
    Ismael

    • This reply was modified 11 months, 3 weeks ago by Rikard.
    #1426508

    copy&paste error – it is of course a (f)unction in the first line

    #1426510

    Hi,

    Thanks for pointing that out @guenni007 :-)

    Best regards,
    Rikard

    #1426541

    Thank you for the quick reply. This PHP code works to display the burger on scroll, but the sidebar doesn’t shrink (it’s set at 300px currently, and on scroll, I would like to reduce it by x% (same functionality as your top shrinking menu option)). It would be really cool to switch the logo image as well!!!

    Check out this website as an example: https://rndhouse.com

    • This reply was modified 11 months, 3 weeks ago by nTECHgrate.
    #1426561

    try to modify this to your needs:

        (function($) {
            $(document).ready(function () {
                if (window.innerWidth > 989) {
                    var header = $('#header');
                    var main = $('#main');
                    var burger = $('.html_header_sidebar #top div .av-burger-menu-main');
                    var footer = $('.html_header_sidebar.html_header_left .av-curtain-footer.av-curtain-activated .av-curtain-footer-container');
                    var menu = $('.responsive.html_header_sidebar #header .av-main-nav > li').not('.av-burger-menu-main, .av-active-burger-item');
    
                    $(window).scroll(function () {
                      if ($(this).scrollTop() > 200) {
                        burger.show();
                        menu.hide();
                        header.css({'width': '120px', 'transition': 'all 1s ease'});
                        main.css({'margin-left': '120px', 'transition': 'all 1s ease'});
                        footer.css({ 'width': 'calc(100% - 120px)', 'margin-left': '121px'  });
                      } else {
                        menu.show();
                        burger.hide();
                        header.css({'width': '300px', 'transition': 'all 1s ease'});
                        main.css({'margin-left': '300px', 'transition': 'all 1s ease'});
                        footer.css({ 'width': 'calc(100% - 300px)', 'margin-left': '301px'  });
                      }
                    });
                } 
              });
        })(jQuery);

    and you had to find a solution for the opened hamburger then yourself. trying to find a solution for paddings on the hamburger ul
    and – because of the new existing place for main some alb elements are not willing to go with that. F.e. on : https://kriesi.at/themes/enfold-photography/blog/ i can see in developer tools that there wasn’t a recalculation on masonry styles. And you had to find a way to close the hamburger menu when scrolling back to top position.

    #1426562

    Thank you Guenni007,

    I know just enough about this to break things (which is how I learn best).

    When I try to use your code, I receive the following error message:

    Your PHP code changes were not applied due to an error on line 55 of file wp-content/themes/enfold-child/functions.php. Please fix and try saving again.
    syntax error, unexpected ‘$’, expecting variable (T_VARIABLE)

    #1426569

    Hi,
    Please try wrapping Guenni007 code in a function if you are adding it to your child theme functions.php like this:

    function custom_shrinking_sidebar_menu_script() { ?>
      <script>
    (function($) {
      $(document).ready(function () {
          if (window.innerWidth > 989) {
              var header = $('#header');
              var main = $('#main');
              var burger = $('.html_header_sidebar #top div .av-burger-menu-main');
              var footer = $('.html_header_sidebar.html_header_left .av-curtain-footer.av-curtain-activated .av-curtain-footer-container');
              var menu = $('.responsive.html_header_sidebar #header .av-main-nav > li').not('.av-burger-menu-main, .av-active-burger-item');
    
              $(window).scroll(function () {
                if ($(this).scrollTop() > 200) {
                  burger.show();
                  menu.hide();
                  header.css({'width': '120px', 'transition': 'all 1s ease'});
                  main.css({'margin-left': '120px', 'transition': 'all 1s ease'});
                  footer.css({ 'width': 'calc(100% - 120px)', 'margin-left': '121px'  });
                } else {
                  menu.show();
                  burger.hide();
                  header.css({'width': '300px', 'transition': 'all 1s ease'});
                  main.css({'margin-left': '300px', 'transition': 'all 1s ease'});
                  footer.css({ 'width': 'calc(100% - 300px)', 'margin-left': '301px'  });
                }
              });
          } 
        });
    })(jQuery);
    </script>
      <?php
    }
    add_action('wp_footer', 'custom_shrinking_sidebar_menu_script', 99);

    In my test this is working, thanks for sharing Guenni007!

    Best regards,
    Mike

    #1426576

    Gentlemen – wow!

    Thank you so much. This is looking great! Two follow-ups if you have it in you:

    1) I would really like to replace the logo image when it scales down as well. Any thoughts on this? And if not, what about removing it all together?
    2) The burger is not centered when it shrinks. Can you please help with that?

    2.5) If you want to send me your address, I will send you a nice bottle of Bourbon (or whatever tickles your fancy).

    I can not thank you enough. This is going to be soooo Cool!

    -James

    #1426577

    Hi,

    Thank you for the update.

    1.) To add an alternate logo on scroll, please update the script with the following code.

    
    function custom_shrinking_sidebar_menu_script() { ?>
        <script>
      (function($) {
        $(document).ready(function () {
            if (window.innerWidth > 989) {
                var html = $('html');
                var header = $('#header');
                var main = $('#main');
                var logo = $('.logo a'); 
                var logo_alt = $('<img src="IMAGE_URL_HERE" class="av-logo-on-scroll" height="100" width="300" alt="Griegos Farms" title="">').appendTo(logo).hide();
                var burger = $('.html_header_sidebar #top div .av-burger-menu-main');
                var burger_icon = burger.find('.av-hamburger');
                var footer = $('.html_header_sidebar.html_header_left .av-curtain-footer.av-curtain-activated .av-curtain-footer-container');
                var menu = $('.responsive.html_header_sidebar #header .av-main-nav > li').not('.av-burger-menu-main, .av-active-burger-item');
      
                $(window).scroll(function () {
                  if ($(this).scrollTop() > 200) {
                    burger.show();
                    menu.hide();
                    logo_alt.show();
                    logo.hide();
                    header.css({'width': '120px', 'transition': 'all 1s ease'});
                    main.css({'margin-left': '120px', 'transition': 'all 1s ease'});
                    footer.css({ 'width': 'calc(100% - 120px)', 'margin-left': '121px'  });
                  } else {
                    if(burger_icon.hasClass('is-active') == false)
                    {
                        menu.show();
                        burger.hide();
                        logo_alt.hide();
                        logo.show();
                        html.css('overflow', 'auto');
                        header.css({'width': '300px', 'transition': 'all 1s ease'});
                        main.css({'margin-left': '300px', 'transition': 'all 1s ease'});
                        footer.css({ 'width': 'calc(100% - 300px)', 'margin-left': '301px'  });
                    }
                  }
                });
            } 
          });
      })(jQuery);
      </script>
        <?php
      }
      add_action('wp_footer', 'custom_shrinking_sidebar_menu_script', 99);
    

    Make sure to update the logo or image URL in this line.

    var logo_alt = $('<img src="IMAGE_URL_HERE" class="av-logo-on-scroll" height="100" width="300" alt="Griegos Farms" title="">').appendTo(logo).hide();
    

    2.) To center align the burger menu, please add this css code.

    @media only screen and (min-width: 989px) {
    
      /* Add your Desktop Styles here */
      #top .av-burger-menu-main.menu-item-avia-special a {
        text-align: center;
      }
    }

    2.5) :D

    Best regards,
    Ismael

    #1426588

    i’m so sorry – i pasted only the function above that i tested on the demo pages with developer tools.
    i forgot to wrap it as Mike said for the child-theme functions.php.
    ________

    See how a test on dev tools work with script :
    Just open the console and enter the function you like to test. Return – and test

    click the gif to see the video:

    #1426620

    Guenni007,

    Thank you for the tip. That is a great tool to add to the toolbox.

    -James

    #1426621

    Ok team, we are so close.

    3) The code that Ismael last provided adds the new logo but does not remove the previous one – see screenshot here.

    4) When clicking on the burger to use the menu, the menu items are not on the screen – you have to scroll down to see them. Furthermore, if you scroll down/up far enough, the web page starts to move in the background, which triggers the normal menu to reappear, making it very confusing to get out of – see a video of this here: http://jamesj173.sg-host.com/wp-content/uploads/2023/11/Shrinking-side-menu-issues.mp4

    Thank you again for all your help with this. This seems like a really cool feature that Enfold could add in a future release.

    • This reply was modified 11 months, 3 weeks ago by nTECHgrate.
    • This reply was modified 11 months, 3 weeks ago by nTECHgrate.
    #1426662

    Hi,

    Thank you for the screenshots.

    3.) We adjusted the script a bit to hide the initial logo on scroll and prevent it from reverting back while the burger overlay is active.

    // https://kriesi.at/support/topic/shrinking-side-bar-menu/#post-1426577

    4.) You can adjust the padding with this css code.

    @media only screen and (min-width: 989px) {
    
      /* Add your Desktop Styles here */
      #top #av-burger-menu-ul {
        padding: 100px 0 !important;
      }
    }
    
    

    Best regards,
    Ismael

    #1426663

    Ismael,

    Thank you, sir. This is so close. Your update does remove the the original logo now, which is great, but it no longer loads the secondary one.

    video here

    -James

    • This reply was modified 11 months, 3 weeks ago by nTECHgrate.
    #1426666

    Hi,

    Did you remove the script? The alternate logo doesn’t display because it uses http instead of https. Please check the private field.

    Best regards,
    Ismael

    #1426668

    I added it back so you can see it. I also changed the image url to https but I get the same thing.

    #1426680

    the point is that logo.hide() will hide the whole anchor. ( including the alt-logo)
    you had to be more specific in your selector

    btw. i would work with an svg logo ( you know your fonts ( Dante and Tribute) so you only had to vectorize the “i” plant.
    i would place both parts in that svg – like this ( where the plant part is set to opacity: 0 from the beginning – only here to see where it is and what dimension it could have.)

    the rest is easy then – you can influence and animate the show and hide of the svg parts by ID:

    https://weber.tips/

    #1426684

    Hi,

    We edited functions.php file and adjust the following line a bit. Please make sure to purge the cache before testing the page.

     var logo = $('.logo a img'); 
                var logo_alt = $('<img src="https://jamesj173.sg-host.com/wp-content/uploads/2023/11/Griegos_Branch_BLK.png" class="av-logo-on-scroll" height="100" width="300" alt="Griegos Farms" title="">').appendTo(logo.parent('a')).hide();
    

    Best regards,
    Ismael

    #1426688

    yes – now it works well. so do not change now your setting.
    but keep in mind that svgs are a mighty image format – you can influence from outside by css. And often much smaller in file-size and with maximum sharpness.

    PS: if your Logo could be changed a bit – ( like i do ) it would be nice to easier identify the “plant” as the missing “i” in Griegos.
    We as layout-savvy users see this immediately, but a normal visitor to the site may not.

    #1426711

    A HUGE THANK YOU TO EVERYONE!!!

    This works great now — so cool!!!

    Guenni007, thank you for the tip. I like it a lot and will try that out.

    Enfold team, you can close this ticket.

    Thank you, thank you, thank you.

Viewing 21 posts - 1 through 21 (of 21 total)
  • The topic ‘Shrinking side bar menu’ is closed to new replies.