title: Two menu effects in one JQuery
body: <p>for several days I have been trying to combine these 2 effects so that they work on the same menu but without effective. Do any of you have any idea what it should look like, should it work properly and not have many loops at the same time? Of course, the code, as each effect should work, is provided in the link. Thank you for your help :)</p>
  <p><strong>Preview how each effect works:</strong>
  <a href="https://jsfiddle.net/vw6zs8kp/" rel="nofollow noreferrer">https://jsfiddle.net/vw6zs8kp/</a></p>
  <p><strong>JavaScript Code:</strong></p>
  <pre><code>;(function($){&quot;use strict&quot;;
  var line = $('#sf-arrows, #line'), item_default = $('.menu-item.item-active'), item_width = $('.item-active').width(), position_left = $('.item-active').position().left;
  $('.menu-item').on(&quot;classChange&quot;, function(){
      item_default = $('.menu-item.item-active'), item_width = $('.item-active').width(), position_left = $('.item-active').position().left;
  });
  line.css({left: position_left, width: item_width});
  let items = $('.sf-menu &gt; .menu-wrapper &gt; .nav-menu').children('li');
  items.each(function(){
      var item = $(this), menu_item = item.children('a.js-scroll-trigger[href*=&quot;#&quot;]:not([href=&quot;#&quot;])');
      $(menu_item).on(&quot;click&quot;, function(){
          if(location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') &amp;&amp; location.hostname == this.hostname){
              var target = $(this.hash);
              target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
              if(target.length &amp;&amp; $(item).is(':visible')){
                  $('html, body').animate({scrollTop: (target.offset().top - 56)}, 1000, &quot;easeInOutExpo&quot;);
                  return false;
              }
          }
      });
      $(window).scroll(function(){
          var i = 0;
          menu_item.each(function(index, id){
              if(location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') &amp;&amp; location.hostname == this.hostname){
                  var target = $(this.hash);
                  target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
                  if(target.length &amp;&amp; $(item).is(':visible')){
                      item.removeClassClass('item-active');
                      if(($(window).scrollTop() + 56)&gt;=(target.offset().top - 56) &amp;&amp; ($(window).scrollTop() + ($('main &gt; section[id]')[(i+1)].offsetTop - (target.offset().top + target.height())))&lt;=(target.offset().top + target.height() - 56)){
                          item.addClass('item-active');
                          i++;
                      }else{
                          $(id.parentElement).removeClass('item-active');
                      }
                  }
              }
          });
      });
      $(this).mouseenter(function(){
          item_width = item.width(), position_left = item.position().left;line.css({left: position_left, width: item_width});
      });
      $(this).mouseleave(function(){
          item_width = item_default.width(), position_left = item_default.position().left;line.css({left: position_left, width: item_width});
      });
  });})(jQuery);
  </code></pre>