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

  • Home
  • SEARCH
  • 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 8089459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:24:07+00:00 2026-06-05T19:24:07+00:00

I have wrote a script to detect when I reach the div element which

  • 0

I have wrote a script to detect when I reach the div element which is a navigation bar and then I change it’s css to position fixed and top 0 so it will be fixed to the top, the problem that it doesn’t do that, it acts like scroll to top and it jumps to the beginning of the screen. (it’s flickers)

Javascript

        var currentScrollTop = 0;
        var barMenuOriginalTopPos = $('#navigation').offset().top;
        console.log('original:' + barMenuOriginalTopPos);
        $(window).scroll(function() {

            currentScrollTop = $(window).scrollTop();
            console.log(currentScrollTop);
            if(currentScrollTop >= barMenuOriginalTopPos && $('#navigation').hasClass('fixElementToTop') == false){
                $('#navigation').addClass('fixElementToTop');
            }
            else if(currentScrollTop < barMenuOriginalTopPos && $('#navigation').hasClass('fixElementToTop') ){
                $('#navigation').removeClass('fixElementToTop');
            }
        });

CSS

.fixElementToTop { position: fixed; top:0; z-index:100;}

Why

  • 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-05T19:24:09+00:00Added an answer on June 5, 2026 at 7:24 pm

    a css fixed bar on top of the screen

    <div style="position:fixed;top:10px;left:10px">Nav bar</div>
    

    Review:

    sorry i didn’t understand your initial question, here it goes, to avoid it flicking you should start the object with a fixed position, lets say:

    <div style="height:120px">XXX</div>
    <div id="navigation" style="position: fixed; top:120; z-index:100;">Navigation</div>
    <div class="win" style="border: 1px solid; height: 900px;"></div>
    

    the code:

    $(window).scroll(function() {
        currentScrollTop = 120-$(window).scrollTop();
        console.log(currentScrollTop);
        if (currentScrollTop<0) currentScrollTop=0
        $("#navigation")[0].style.top=currentScrollTop+"px";
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have wrote this little script which generates a nice random password. The problem
Suppose I have wrote script Table_ABC.sql which creates table ABC. I have created many
i have wrote a script to produce an array of data but now want
I have wrote a script to do some backup. There is a if block
I have a Perl script I wrote for my own personal use that fetches
I have a radcombobox with checkboxes turned on. I wrote a jQuery script to
I have an interesting problem. I wrote the following perl script to recursively loop
I have to write a script which will be hosted on differents domains. This
I want to write a PHP script which will first detect URL's and see
I wrote a script of my portfolio, which works almost how I want it,

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.