floating a div with jquery/offset - ignores href hashtag
Posted
by
Kevin Crawley
on Stack Overflow
See other posts from Stack Overflow
or by Kevin Crawley
Published on 2012-09-13T21:30:08Z
Indexed on
2012/09/13
21:38 UTC
Read the original article
Hit count: 219
<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.
© Stack Overflow or respective owner