floating a div with jquery/offset - ignores href hashtag
- by Kevin Crawley
<script type="text/javascript">
$(document).ready(function () {
var top = $('#rt_outer').offset().top - parseFloat($('#rt_outer').css('marginTop').replace(/auto/, 0));
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
// whether that's below the form
if (y >= top) {
// if so, ad the fixed class
$('#rt_outer').addClass('fixed');
} else {
// otherwise remove it
$('#rt_outer').removeClass('fixed');
}
});
});
</script>
The problem is fairly straight forward. If I use a header redirect to a new location in the page (say half way down, I jump to #halfway after processing a php script using header("somepage.php#halfway") the div container which is handled by this script won't jump down until the page is scrolled in either direction.
I know there is a solution to this, I just don't know what.