PDA

View Full Version : jQuery/CSS : Scrolling sidebar, how to change position?



TGoodman
16 Jul 2010, 10:46 AM
In the following: http://tiny.cc/pvzw1

I need the scrolling box on the right to jump to the other side of the page once the user scrolls and hits the fold. I am not sure if this is a CSS issue or a jQuery issue. Right now I am just working with the example code. Would it be possible to have this block move after the initial scroll and then stick to the left side?


<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'></script>
<script type="text/javascript">
$(function() {
var offset = $("#sidebar").offset();
var topPadding = 15;
$(window).scroll(function() {
if ($(window).scrollTop() > offset.top) {
$("#sidebar").stop().animate({
marginTop: $(window).scrollTop() - offset.top + topPadding
});
} else {
$("#sidebar").stop().animate({
marginTop: 0
});
};
});
});
</script>