error at work scrollify.js when moving behind the anchor

36 Views Asked by At

the problem is... when I go to the anchors in the menu at the top of the page (to a block that is more than 100vh), everything is fine, but when I am at the bottom of the page and want to go to the anchor to this block, I am first transferred to the anchor, and then scroll down the block how to solve it? I tried to solve it like this, but it didn't work

$(function () {
  var lastScrollTop = 0;
  var isAnimatingScroll = false;

  $.scrollify({
    section: ".scrolls",
    scrollSpeed: 1500,
    scrollbars: true,
    hashTags: false,
    updateHash: false,
    before: function () {
      $('.scrolls').removeClass('active');
      current = $.scrollify.current();
      current.addClass('active');
    },
  });

  $('a[href^="#"]').on('click', function (e) {
    e.preventDefault();
    
    if (isAnimatingScroll) return;

    var target = $(this).attr('href');
    var offset = $(target).offset().top;

    isAnimatingScroll = true;
    $.scrollify.disable();

    $('html, body').animate({ scrollTop: offset }, 1000, function () {
      isAnimatingScroll = false;
      $.scrollify.enable();
    });
  });

  $(window).on('scroll', function () {
    var scrollTop = $(this).scrollTop();

    if (scrollTop > lastScrollTop) {
      $('header').addClass('header-hidden');
    } else {
      $('header').removeClass('header-hidden');
    }

    lastScrollTop = scrollTop;
  });
});
0

There are 0 best solutions below