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 8989703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:19:35+00:00 2026-06-15T22:19:35+00:00

The Question: The Link to an Example: http://jsfiddle.net/j65yQ/ /* First: */ /* Set the

  • 0

The Question:

The Link to an Example: http://jsfiddle.net/j65yQ/

/* First: */
/* Set the Position of the Division Tag to Fixed When Reaching the Top of the Window While Scrolling */
            
$(window).scroll(function(){ 

    var u_div_cn = $('div#container_nav');
    var u_os_top_read = $('div#container_nav').offset().top;
    
    if ($(window).scrollTop() > u_os_top_read) {      
    u_div_cn.addClass('set_position');};

});

Which resulting value does .scrollTop() get when scrolling?

The division tag in the above example does set its position attribute to fixed by the conditional if statement when it has reached the top of the window.

Yet, why does in this example "greater than" .offset().top work, in contrast to "equals to" zero, which has not worked after many tries?

As an Example for the "Equals To":

$(window).scroll(function(){    

    var u_div_cn = $('div#container_nav');
    var u_div_cn_os_top = $('div#container_nav').scrollTop();
    
 
    if ( u_div_cn_os_top ==  0 ) {      
        u_div_cn.addClass('set_position');
    };

});

The reason why I am asking is, because I thought of the equals to to work as well right at top: 0 of the window.

  • 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-15T22:19:36+00:00Added an answer on June 15, 2026 at 10:19 pm

    The scrollTop function returns how many pixels the content is scrolled down, i.e. how many pixels are outside above the window.

    When scrolling, you won’t get an event for every single pixel that the content is scrolled. If you use the == operator to check the offset, you will miss it most of the time. Using the > operator ensures that the element will become fixed as soon as its top moves out of the window at the top.

    If you compare the value from scrollTop to zero, that will only be true if you scroll down, and then scroll back up to the top.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question has gotten rewritten. An Example: Here is an example HTML page: http://jsfiddle.net/mwMzD/2/
In the following link: http://jsfiddle.net/gCvbT/ , if you click on General and then click
I have an example: http://jsfiddle.net/kamaci/uVQZc/3/ When I animate bigger blue div, I want to
Example code: http://jsfiddle.net/slolife/PnmxM/ I am asking this even though there are a number of
I have a visual list of items like this: http://jsfiddle.net/viatropos/XCe3T/1/ In the real app,
http://jsfiddle.net/kCMvt/ Hey everyone. I made this jQuery page for a mobile phone, but the
The link below will take you to my example. My question is... without changing
say, i have such xml file: <?xml version=1.0?> <catalog> <title>My book catalog</title> <link>http://example.com/catalog</link> <book
Similar to this question: link However I have already mastered that. My problem is
There is already a similar question( link ).The thing is I don't understand what

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.