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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:47:45+00:00 2026-06-01T03:47:45+00:00

I have made a rediculasly small snippet to make a sub-header stick to the

  • 0

I have made a rediculasly small snippet to make a sub-header stick to the top.
But since , Like I said – I am by no means a js genious or jQuery genious – and actually far from it – I have my doubts about my own coding abilities..

  • the demo is here : http://jsfiddle.net/obmerk99/VvKq3/1/

The questions :

  • 1 – there seems to be a lot of plugins (and a lot of questions also
    in this very site) with much more code than my snippet – what am i
    missing ?? What am I doing wrong ?
  • 2 – will this work cross-browser ?
  • 3 .. and this is a small problem, how to avoid the small “jump” that occurs ?
    (if you go to the fiddle, and scroll slowly – you will see that the main div “jumps” when the script is evoked ..
    I have tried to add another .pad class to the lower divs –

added class : .pad when script evoked.

.pad{padding-top:42px;}

but it does not seems to work right : http://jsfiddle.net/obmerk99/VvKq3/2/

  • 5 .How can I calculate the real position of the div ? when I try
    something like this :
var top = jQuery(window).scrollTop();

var div_top =  jQuery('#header_stick').offset().top;

if (top > div_top) // height of float header;

it is jumpy … http://jsfiddle.net/obmerk99/VvKq3/4/

  • 6 any other suggestions are welcome..
  • 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-01T03:47:46+00:00Added an answer on June 1, 2026 at 3:47 am

    The “jumping” occurs because the element was occupying space in the parent element, and when you change its position to fixed it’s suddenly not anymore. I don’t know the best way to handle it, but one option would be adding a small span (maybe with a single space) just before your #header_stick, with the same height of it, so when it’s class is changed there will still be something there to account for the height difference. (Update: your pad solution is probably the best one, once done right; see below)

    Your padding solution might also work, provided that: 1) you remember to remove that class when the user scrolls to the top (in your fiddle I see you adding it, but don’t see you removing it); 2) You get the height right – I still couldn’t look closely to your code, so I don’t know where you got wrong. (Edit: the problem was that your .pad class was using the height of the floating header, not the stick header – fixing that and removing the class yielded what I believe to be the correct result)

    About the real position of the div, have you tried subtracting the div’s offset from the offset of the parent element? This way you’ll have its position relative to the parent (pay attention to things like borders, though – I’ve recently answered another question where details like this mattered).

    Update: your problem here seems to be that, when the position is changed to fixed, the offset also varies wildly. I’d suggest calculating the correct height, once, then storing it somewhere so the scroll function can use it. In other words, don’t calculate it while scrolling, that makes it much more difficult to find the right theshold to do the class switch.

    Other than that, I think you’re code is fine, and I believe it will work cross browsers too (at least standards compliant ones; can’t say anything about old versions of IE). Very insightful too, I always wondered how this “trick” worked, now I see it’s simpler than I imagined…

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

Sidebar

Related Questions

I have made a working clock widget app in android but would like it
I have made a cart and the cart has remove item button, but the
I have made an iphone application like flip cards in which values of cards
I have made an mvc3 application with Windows Authentication. Everything works fine but I
I have made a simple timer but in trying to increase the timers speed
I have made a small program in C# that I want to run in
I have made one file say a.php. Now I want some thing like if
I have made my Actor , but I am unclear on how to take
I have made a form for client registration, and I can't make this postvalidators
I have made a Highcharts chart with grouped and stacked columns, like in the

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.