Archived topic
Anchor in menu 40px (?) too far down
8 replies · Started by Torsten on April 5, 2023
Hi,
how can I adjust the anchor so that e.a. menu point "Referenzen" is reached a few pixel up, for the moment I have a white space above the "Referenzen"-section and the header on all display sizes...
thx ahead,
Torsten.
Hi Torsten,
Try setting the Anchor id to this text instead "Designberatung" which is right below "Referenzen".
Hi Fernando,
all anchors are "misplaced" by about the same amount. And as I'm using different widgets and display options (toggle visibility) for desktop, tablet and/or mobile I had an issue with the slide-out menu not working except for desktop previously.
Therefore I need a code to set an offset for all anchors the same amount.
best,
Torsten
Can you try adding this through a Hook Element:
<script>
jQuery(function($) {
$('li.smooth-scroll > a[href*="#"]:not([href="#"]), a.smooth[href*="#"]:not([href="#"])').on( 'click', function(e) {
e.preventDefault();
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top + 100
}, 500);
}
}
});
});
</script>
Hook it to wp_footer.
Hi Fernando,
I added the code, see screenshot-link in private information.
No changes, I tried as well changing the values...
best,
Torsten
Hi,
I added a screenshot in private information with 6 Menu items (I wrote each menu item beside the burger menu in red) and marked the offset in each with 2 red lines, like this it is obvious that it's the same offset for each widget / section.
best,
Torsten
Hi there,
that looks real tricky, the only way i would think you could make that work consistently is if the page was split into sections and each section had the anchor attached to it.
you would also need to make sure the site header was a constant height.
That way you have consistency for the anchor positioning.
was worth the try.
Thx for the effort,
best,
Torsten
You're welcome