2

I would like to create a header that contains graphics/images and when the user scrolls down to view the page content, the header starts off at the base and then becomes fixed at the top of the screen.

Here is an example: http://www.thinkful.com/learn/javascript-best-practices-1/

How would I create this?

Jay
  • 185
  • 2
  • 7
  • 21
  • 1
    Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include **attempted solutions**, **why they didn't work**, and the expected results. – showdev Oct 07 '13 at 23:49
  • i've looked on google and haven't found any tutorials. I have no idea where to begin. – Jay Oct 07 '13 at 23:50
  • 2
    @Jay - Googling *"How do I create a header that rolls into a sticky nav bar?"* brings up at least three step-by-step tutorials and one stackoverflow question. – Joe Oct 07 '13 at 23:53
  • Thanks @Joe. Also, I suggest that you check the "related" sidebar on this page. – showdev Oct 07 '13 at 23:54
  • NO idea where I was looking. I made a big mistake, thank you. – Jay Oct 07 '13 at 23:56
  • @Jay - no problem, I'd recommend taking a look at this one in particular: http://webdesign.tutsplus.com/tutorials/javascript-tutorials/create-a-sticky-navigation-header-using-jquery-waypoints/ - it uses the waypoints plugin mentioned in an answer. – Joe Oct 07 '13 at 23:57
  • @Joe Perfect, I really appreciate it! – Jay Oct 08 '13 at 00:12

3 Answers3

2

I have used jQuery Waypoints (http://imakewebthings.com/jquery-waypoints/) with a lot of success.

Kate McCubbins
  • 793
  • 4
  • 9
2

By checking scrollTop(). You could easily have searched for this. How to build simple sticky navigation with jQuery?

Community
  • 1
  • 1
Colandus
  • 1,634
  • 13
  • 21
1

Using jQuery:

  1. With $(window).on('scroll',function(){ /*your code*/ }); you can bind a function to the scroll event.

  2. Inside that function use document.scrollTop to know the current vertical position of the scroll bar

  3. Change the css of the header and the side menu with .css() or .addClass()

  4. Finally with the HTML5 History API you can change the URL without loading the page using the history.replaceState() method.

I've just forked a plugin called Scrollit.js that does the job. The original version from Chris Polis works great but doesn't change the URL. My version does change the URL has't been completely tested.

El Cultivo
  • 64
  • 3