Lagging when pressing menu

Hello.

I have 2 questions regarding the one page menu.

Question 1:
I couldnt get the menu to scroll properly when i pressed the menu items.
I found out that was a bug in the new version.
So i added this code which i found here on the forum:

jQuery(document).ready(function($) {
function scrollToSection(event) {
event.preventDefault();
var $section = $($(this).attr(‘href’));
$(‘html, body’).animate({
scrollTop: ($section.offset().top - $(’.x-navbar-wrap’).outerHeight())
}, 1000);
}
$(’.menu-item a’).on(‘click’, scrollToSection);
}(jQuery));

It now scrolls.
But after a click or 2 it starts lagging heavily?
Is there anything in the code that does it or is it too heavy pictures on the site?

Question 2:
How do i make the “Hjem”(Home button) button scroll to the top and show as active all the way down to the next item.
I just linked it to #top. That works, but the active disapers until i scroll down a bit.

Site im referring to is : www.luftspeil.no

Thanks in advance!

Hello Jim,

Thanks for writing in!

1.) Please update your code and make use of this one:

jQuery(document).ready(function($) {
  function scrollToSection(event) {
    event.preventDefault();
    var $section = $($(this).attr('href'));
    console.log($section);
    $('html, body').animate({
      scrollTop: ($section.offset().top - $('.x-navbar-wrap').outerHeight())
    }, 1000);
  }
  $('.menu-item a').on('click touchstart', scrollToSection);
}(jQuery));

2.) Please remove #top as the menu item link and use #hjem instead.

We would love to know if this has worked for you. Thank you.

Hello.

Thanks for replying.
I fixed the code. The scrolling seems a little better now.

Regarding the top menu. If you go on the site, it doesnt show active on “Hjem” if you scroll all the way up. But if you scroll a little bit down it does.
Is that normal behaviour?

/Jim

Hey Jim,

Yes. It is normal behavior. The highlighter only works when you begin to scroll.

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.