• Hi,

    i′m creatign custom theme with sticky header after scroll and also with smooth scroll to an anchor. Website: https://startupweb.sk/

    First time the page loads (or when the page is entirely at the top) and I click on page – ?o robíme or portfolio (doesn′t matter) page scroll down but header overlaps title. When I scroll with mouse and then I press menu items, page scroll to anchor link perfect. Only when page si entirely at the top, scrolling ins′t perfect.

    Code for sticky header:

    $(function() {
    var stickyNavTop = $('.navigation').offset().top;
    
    var stickyNav = function(){
    var scrollTop = $(window).scrollTop();
    
    if (scrollTop > stickyNavTop) {
        $('.navigation').addClass('sticky');
    } else {
        $('.navigation').removeClass('sticky');
    }
    };
    
    stickyNav();
    
    $(window).scroll(function() {
        stickyNav();
    });
    
    });
    
    Code for smooth scroll:
    
    $(function() {
      $('a[href*="#"]:not([href="#"])').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
          var target = $(this.hash);
          target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
          if (target.length) {
            $('html, body').animate({
              scrollTop: target.offset().top -60
            }, 1000);
            return false;
          }
        }
      });
    });

    Please, could you help me and give me some advice what should i change.
    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Do you only see this logged in ? in that case you can add a class to your body tag, WordPress will set that for you.

    WP Codex body_class()

    Thread Starter morene

    (@morene)

    Thanks for answer.

    Yes, i see it when I am logged in and logged out too. I added class .shifted to body_class(). Now it is ok, but my sticky header is “broken” because i have border around body – 30px solid gray. My sticky scroll effect disappeared. Now my header is entirely at the top and you can′t see border-top for body.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sticky header with smooth scroll’ is closed to new replies.