bzcomputers
Well-known member
I am working on some custom pages with #target links within the page, currently in the form of a table of contents at the top of the page. The issue is, the targeted positions are all off by -45px due to the fixed header at the top of the page.
I see somehow this is not an issue for #target links within the XenForo forum (for instance post links). It appears this offset is already compensated for through existing script.
Where is this script and what do I need to do to have it active on a custom page?
My alternative is to run some additional jQuery smooth scrolling code like below:
	
	
	
		
Then I can add a data-offset field to the scroll link:
	
	
	
		
...but if it is already done within XenForo I might as well use the existing code.
				
			I see somehow this is not an issue for #target links within the XenForo forum (for instance post links). It appears this offset is already compensated for through existing script.
Where is this script and what do I need to do to have it active on a custom page?
My alternative is to run some additional jQuery smooth scrolling code like below:
		JavaScript:
	
	$('.scroll').on('click',function(e) {
    e.preventDefault();
    var offset = 0;
    var target = this.hash;
    if ($(this).data('offset') != undefined) offset = $(this).data('offset');
    $('html, body').stop().animate({
        'scrollTop': $(target).offset().top - offset
    }, 500, 'swing', function() {
        // window.location.hash = target;
    });
});Then I can add a data-offset field to the scroll link:
		HTML:
	
	<a class="scroll" href="#target" data-offset="45">Scroll to Target</a>...but if it is already done within XenForo I might as well use the existing code.
 
 
		 
 
		
 
 
		