Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:13:21+00:00 2026-06-05T15:13:21+00:00

First off I use this code to make the navigation bar always stay fixed;

  • 0

First off I use this code to make the navigation bar always stay fixed;

After adding CSS position absolute:

var yOffset = $("#header").offset().top;
$(window).scroll(function() {
    if ($(window).scrollTop() > yOffset) {
        $("#header").css({
            'top': 0,
            'position': 'fixed'
        });
    } else {
        $("#header").css({
            'top': yOffset + 'px',
            'position': 'absolute'
        });
    }
});

But now my next/previous key events which used to scroll to next element is not catching the right element position.

here is my code for browsing next/prev element.

// scroll to next post
function scrollToNew () {
  scrollTop = $(window).scrollTop();
  $('.post').each(function(i, h1){
    h1top = $(h1).offset().top;
    if (scrollTop < h1top) {
      $.scrollTo(h1);
      return false;
    }
  });
}

// scroll to previous post
function scrollToLast () {
  scrollTop = $(window).scrollTop();
  var scrollToThis = null;
  $('.post').each(function(i, h1) {
    h1top = $(h1).offset().top;
    if (scrollTop > h1top) {
      scrollToThis = h1;
    } else {
      return false;
    }
  });
  if(scrollToThis != null) {
    $.scrollTo(scrollToThis);
  }
}

I simply used to fire the scrollToNew when key pressed and it was working until I made the fixed navigation (#header) because it stays always on top so the heading of post which user scrolls to, becomes invisible. I do not know how to get around this issue.

Any suggestions are greatly helpful really.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:13:22+00:00Added an answer on June 5, 2026 at 3:13 pm

    Here is the fix.

    I added the height of navigation header into offset. Which is exact 61pixels. Problems solved.

    // scroll to next post
    function scrollToNew () {
      scrollTop = $(window).scrollTop();
      $('.post').each(function(i, h1){
        h1top = $(h1).offset().top;
        if (scrollTop < h1top - 61) {
          $.scrollTo(h1, {offset: {left: 0, top: -61}});
          return false;
        }
      });
    }
    
    // scroll to previous post
    function scrollToLast () {
      scrollTop = $(window).scrollTop();
      var scrollToThis = null;
      $('.post').each(function(i, h1) {
        h1top = $(h1).offset().top;
        if (scrollTop > h1top - 61) {
          scrollToThis = h1;
        } else {
          return false;
        }
      });
      if(scrollToThis != null) {
        $.scrollTo(scrollToThis, {offset: {left: 0, top: -61}});
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off: I do not want to use JQuery, i know it would make
First off i want to say im attempting (and mostly succeeding) to use purely
First off the html row looks like this: <tr class=evenColor> blahblah TheTextIneed blahblah and
First off here is the code! <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
First off, I'm aware this is a bad practice and I have answered many
First off, a big thanks to the people behind the new boost::geometry library! This
First off, this may be the wrong Forum for this question, as it's pretty
Here's my wild and whacky psuedo-code. Anyone know how to make this real? Background:
First off i'm new to Linux programming so apologies if this makes no sense
First off, I'm a beginner. If this is way beyond the scope of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.