Here is an enhanced version of http://jsbin.com/ijexe. I have updated the code to restore the original position once it reaches its initial top position, allowing it to start scrolling again.
To test this improvement, you can replace the jQuery function in the http://jsbin.com/ijexe code with the one below...
In the
<script type="text/javascript" src="Sandbox_files/jquery.min.js"></script>
within the example:
.fixedElement {
Z-INDEX: 100; POSITION: absolute; BACKGROUND-COLOR: #c0c0c0; WIDTH: 100%; HEIGHT: 30px; COLOR: #800000; FONT-SIZE: large; TOP: 200px
}
(ensure that your position is set to absolute & top value)
Updated function (insert before the closing body tag)
<script type="text/javascript">
$(window).scroll(function(e){
var scrollTo = 200;
var scrollClass = '.fixedElement';
$el = $(scrollClass);
position = $el.position();
if ($(this).scrollTop() > scrollTo && $el.css('position') != 'fixed'){
$(scrollClass).css({'position': 'fixed', 'top': '0px'});
} else if ((position.top < scrollTo) && ($el.css('position') != 'relative')){
$(scrollClass).css({'position': 'relative', 'top': '200px'});
}
});
</SCRIPT>
You can customize:
scrollTo - The distance from the top of the screen to trigger the element's scrolling behavior
* Make sure the scrollTo value matches your stylesheet declaration...
scrollClass - The class name for the element(s) where the function should be applied