Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1132482

    I have a function that makes the navigation menu sticky. When I want to use this function for more navigation menus, do I have to copy the whole function custom_script2, or can I add more nav_menu ID’s to the same function? For instance, I would also like this function to apply for #nav_menu-16

    function custom_script(){
      ?>
      <script>
    (function ($) {
      function a() {
        $(window).scroll(function (e) {
          var $sticky = $('#nav_menu-10');
          var position = ($sticky.css('position') == 'fixed');
          if ($(this).scrollTop() > 100 && !position) {
            $sticky.css({ 'position': 'fixed', 'top': '150px', 'width': $sticky.innerWidth() });
            $sticky.next().css('float', 'right');
            $sticky.addClass('fixed_element_style');
          }
          if ($(this).scrollTop() < 100 && position) {
            $sticky.css({ 'position': 'static', 'top': '0px', 'width': '' });
            $sticky.next().css('float', 'left');
            $sticky.removeClass('fixed_element_style');
          }
        });
      }
    
      a();
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_script');
    #1132611

    Hey guttogjente,
    In this case I believe you will find it easier to copy the whole function and change the key parts so the two can work at the same time. This will also assist you in the future when you wish to remove it, or change it, instead of trying to recall how the function works.

    Best regards,
    Mike

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.