Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sticky header CSS / JS

Tags:

javascript

css

I found this website today http://www.forward-thinker.co.uk/. Does anyone know how to make a sticky header like this.?

like image 864
DaveS Avatar asked Aug 02 '11 13:08

DaveS


2 Answers

That particular site utilizes jQuery's $(window).scroll event. It checks if the top of the scrolled-to area ($(this).scrollTop();) is below a certain height. If so, it adds to css of the header a class containing position:fixed (it also changes its height, since only part of the header scrolls). If the scrolled-to area is nearer to the top, the script removes the class containing position:fixed from the header's css and changes the height back to its original value.

like image 68
NickAldwin Avatar answered Sep 19 '22 17:09

NickAldwin


It's a technique called "sticky scroll" or "scroll follow"

I found some tutorials for you:

On Nettuts

or here

or here

or here

or here

and there's a resource here:

Jquery Stalker

like image 45
Rdpi Avatar answered Sep 21 '22 17:09

Rdpi