how to make a div scroll up and fix at the top

css, jquery

Solution

Write like this:

$(window).scroll(function () {
                    var height = $('body').height();
                    var scrollTop = $(window).scrollTop();

                      if(scrollTop>500){
                          $('#header').css({ 'position': 'fixed', 'top' : '0' });
                    }
                      else{
                         $('#header').css({ 'position': 'relative', 'top': '500px'});
                       }
                });

Check this http://jsfiddle.net/68eXM/14/

Problem

I am new to jquery and looking to make a div scroll up and fix at the top after i scroll down a particular position in the browser just like http://www.airbnb.com/jobs/

Original source

Related problems