You can try something like below:
function banner(){ var _barOffset = $('#top-bar').outerHeight(), _navOffset = $('#navigation').offset().top, _triggerOffset = _navOffset-_barOffset; $(window).scroll(function() { var _scroll = $(window).scrollTop(); if (_scroll >= _triggerOffset) { $('#top-bar').css({'position':'absolute','top':_triggerOffset - (_scroll-_triggerOffset)}); } }); } banner();
This code is very unverified, however, what we do initially sets the element to an absolute position and defines the top of this element as _triggerOffset, then we take the difference between the current scroll and triggerOffset and subtract it from the top position to make the panel move up, so more you scroll down.
I'm not sure what you meant, but I would look at such a solution. You might want to add some conditions to ensure that the top level never falls below 0 or the browser disappears from the screen.
source share