• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.3 How to fix incorrect anchor positions because of sticky header?

Stuart Wright

Well-known member
#1
When a site has a sticky header (like AVForums), the desired position of an anchor becomes offset by the height of the stuck header.
So scrolling to a particular post in a thread (like when a member opens a thread and it scrolls to the first new post since they last visited), actually scrolls too far down.
Illustrated here. When scrolling to post #5668, we want to see this:

1.jpg

But what we actually see is

wrong.jpg

How can I fix this please?
 
#2
Needed 3 Hours to solve this problem :D

Add this Javascript Code in Header:

<script type='text/javascript'>

$(document).ready(function () {
$('a').on('click', function (e) {
// e.preventDefault();

var target = this.hash,
$target = $(target);

$('html, body').stop().animate({
'scrollTop': $target.offset().top-95
}, 900, 'swing', function () {
});

console.log(window.location);

return false;
});
});

</script>
Thats all, with "top-95" you can choose the position you need.