0

In browsers such as Safari and Chrome for Mac, when you try to scroll up when at the beginning of a page, you are still able to scroll up a little bit, but with resistance, and the page bounces back when you let go.

I have a navbar going across the top of my page. When the user scrolls up past the top of the page, the navbar moves down with the rest of the page, as in this demo video. How can I make the navbar stay at the top of my page even during this scrolling?

Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
Kian Cross
  • 1,818
  • 2
  • 21
  • 41
  • so, you want the navbar to stay at the top of the page ? – Arun AK Jun 20 '16 at 06:47
  • Can you create a jsfiddle for this. – frnt Jun 20 '16 at 06:48
  • @Thinker Only when the page 'bounces' so there isn't the white space at the top. In all other cases the navbar will stay at the stop of the page and when the page scrolls it will move out of view as it normally would. – Kian Cross Jun 20 '16 at 06:48
  • Could you show what you have tried? – Kode.Error404 Jun 20 '16 at 06:55
  • I think it'd be helpful if you showed us a gif or something of what you mean by "bounce". http://www.cockos.com/licecap/ – Adam Zerner Jun 20 '16 at 06:56
  • @frnt Codepen, jsfiddle etc don't have bounce on the output like my browser does. I'll try and make a gif. – Kian Cross Jun 20 '16 at 07:02
  • @AdamZerner [Here](http://g.recordit.co/nz2Sd8ermb.gif). The red bar is the navbar. You can see when I scroll down, the 'bounce' allows a white bar to show at the top. Instead of that, I'd like the navbar to stay stuck to the top. – Kian Cross Jun 20 '16 at 07:07
  • @crossboy007 okay, but your gif is not visible. – frnt Jun 20 '16 at 07:17
  • 1
    @frnt My bad: http://recordit.co/nz2Sd8ermb – Kian Cross Jun 20 '16 at 07:32
  • @crossboy007 got that, can you add your some code over-here. – frnt Jun 20 '16 at 07:44
  • Related question: [Prevent “overscrolling” of web page](http://stackoverflow.com/q/12046315/578288). It’s about making this “bouncing” feature not work at all on a page, instead of making part of the page react to it. – Rory O'Kane Jun 20 '16 at 09:24
  • At code, or a better example. It isn't clear at all what you're after. Also, the content that you add as comments should also be added to your original post so everyone understand what you're doing. – Bram Vanroy Jun 20 '16 at 09:25

3 Answers3

1

I guess you want to create a "sticky header" that stays at the top of the page when you scroll down. You can do that by using CSS "position" rule over your navbar:

position: fixed;
top: 0;

Note: maybe this is a duplicate of this question.

Community
  • 1
  • 1
MmMnMr
  • 111
  • 3
0

Try this solutions, I'm just guessing according to your gif.

  1. html,body{overflow:hidden} (or)
  2. #nav{position:fixed;top:0; or margin-top : 0;} (or)
  3. $("#navbar").css("marginTop",'0')

In 3rd example you can try saving your css value using variable and then by using if condition you can try and may get rid from that bounce effect.

frnt
  • 8,455
  • 2
  • 22
  • 25
0

I think the only way is to disable the bounce effect. Bounce effect is working on the HTML tag itself, so no absolute or fixed positioning will make it stay. Try to apply hidden property to html tag in overflow, like this: html {overflow: hidden}

Pirate X
  • 3,023
  • 5
  • 33
  • 60