The Easter Sale is on! Join now or renew your subscription with a 25% OFF! Read More

Support Forum

Anchor Links Scroll Too Far

Giora
Giora
Offline
Hi Ivo,

Issue: My anchor links land too low

Illustration:
go to http://harborgroupint.com.dedi3509.your-server.de/index.php/firm-overview
click on Offcanvas toggle to get navbar for that page
click on any anchor link there.

I tried to use the onepage menu particle, but it did not work for me in the offcanvas position. So I switched to RokNav.

I see the onepage menu particle uses this:

<ul data-uk-scrollspy-nav="{closest:'li', smoothscroll: {offset: 220}}" data-uk-sticky="{media:768, top:130, boundary: ''}" style="margin: 0px;">


Is there something I can put into my custom.scss file to get my anchor links to land higher on the pages?

TIA!
LIsa

Accepted Answer

Monday, July 10 2017, 08:25 PM - #Permalink
Hi Lisa,

You can use the "Onepage Menu" particle as I showed in the video in your other discussion.

In the "Onepage Menu" particle we use the UIkit Smooth Scroll component, so you can simply create a "Custom HTML" module and write your HTML using the UIkit Smooth Scroll markup. And just use the offset feature to tell where exactly the links should scroll to.

Here, have a look at this video that I recorded for you. It shows everything that I explained above.
The code that I use in the "Custom HTML" module is:

<ul>
<li>
<a href="#g-feature" data-uk-smooth-scroll="{offset: 120}">Section 1</a>
</li>
<li>
<a href="#g-subfeature" data-uk-smooth-scroll="{offset: 120}">Section 2</a>
</li>
<li>
<a href="#g-maintop" data-uk-smooth-scroll="{offset: 120}">Section 3</a>
</li>
<li>
<a href="#g-additional" data-uk-smooth-scroll="{offset: 120}">Section 4</a>
</li>
</ul>


You can of course style your "Custom HTML" module however you like by writing your CSS code in your custom.scss file.
The reply is currently minimized Show
Responses (18)
  • Accepted Answer

    Giora
    Giora
    Offline
    Monday, July 10 2017, 02:35 PM - #Permalink
    I've been trying solutions offered here: https://stackoverflow.com/questions/10732690/offsetting-an-html-anchor-to-adjust-for-fixed-header

    I tried something like

    #anchor {
    display: block;
    position: relative;
    top: -150px;
    visibility: hidden;
    }


    It did not work.

    I tried creating something for each anchor like this:

    a[#g-extension] {
    margin-top: -150px;
    display: inline-block;
    vertical-align: top;
    }


    It did not work.

    What worked was to use something like this within each module:

    <span style="position: relative;"><a style="position: absolute; top: -140px;" name="platform"></a></span>


    and then linking to the module name (#platform) instead of the module position (#g-extension).
    But what I don't like about this is that what works links to the right place in the site on my desktop does not on my laptop.

    TIA for any help you can offer.
    Lisa
    The reply is currently minimized Show
  • Accepted Answer

    Giora
    Giora
    Offline
    Monday, July 10 2017, 08:32 PM - #Permalink
    Ah So Sorry. I did not see your response in the other thread. Going to it now! Thank you!
    The reply is currently minimized Show
  • Accepted Answer

    Monday, July 10 2017, 08:50 PM - #Permalink
    No problem at all ;)
    The reply is currently minimized Show
  • Accepted Answer

    Giora
    Giora
    Offline
    Tuesday, July 18 2017, 12:57 PM - #Permalink
    Ivo,

    In this site: http://forma-fund.com.dedi3509.your-server.de/,
    the off-canvas onepage menu's anchor links work well,
    but my main navigation bar's anchor links land too low on the page
    due to my sticky navigation bar/position.

    In the past you wrote that I can use this code with offset to adjust a link to an anchor:
    Section 1.

    However, after another two days of pulling out my hair, I can't figure out how to get that tag (data-uk-smooth-scroll="{offset: 120}") to work on my main navigation menu buttons.

    I'd really appreciate any help you can offer.

    Best,
    Lisa
    The reply is currently minimized Show
  • Accepted Answer

    Tuesday, July 18 2017, 01:36 PM - #Permalink
    Hi Lisa,

    You are trying to build a complete "One Page" website.
    In that case, please have a look at this discussion and especially my comment there and watch the video in it.

    The jQuery code that you need to add under the "Page Setting" tab in your Base outline is almost the same as in the other discussion. There is just a minor difference that will add the offset. Here's the code that you need to use:

    (function($) {
    $(document).ready(function() {
    $(".g-main-nav .g-toplevel").attr('data-uk-scrollspy-nav', '{closest:".g-menu-item-container", smoothscroll:{offset: 120}}');
    });
    })(jQuery);
    The reply is currently minimized Show
  • Accepted Answer

    Giora
    Giora
    Offline
    Tuesday, July 18 2017, 02:07 PM - #Permalink
    Ivo - YOU ARE THE BEST!!!
    I know this falls outside the Support topics and I know I never could have figured this out on my own.
    So THANK YOU!!!
    I really appreciate this so much.
    Continued success to you!!!!
    Lisa
    The reply is currently minimized Show
  • Accepted Answer

    Tuesday, July 18 2017, 03:16 PM - #Permalink
    You are welcome Lisa!
    And thank you very much for the kind words ;)
    The reply is currently minimized Show
  • Accepted Answer

    Giora
    Giora
    Offline
    Sunday, January 20 2019, 01:11 PM - #Permalink
    Hi Ivo,

    Site: https://www.intego-funds.com/dev/
    Issue: Top navigation bar button links on this one page site are landing too high

    1. I went back to the help you gave me earlier (above) with smooth scroll and top offset:
    https://www.inspiretheme.com/forums/anchor-links-scroll-too-far

    2. I watched this video 5 times:
    https://www.youtube.com/watch?v=kVqQ9hqeq2w&feature=youtu.be

    3. I put this code
    (function($) {
    $(document).ready(function() {
    $(".g-main-nav .g-toplevel").attr('data-uk-scrollspy-nav', '{closest:".g-menu-item-container", smoothscroll:{offset: 120}}');
    });
    })(jQuery);

    into the Base Templates-->Page Settings-->Assets-->Javascript.

    Then I passed it off to Giora who did the same as me above and much more.

    Still the site is not reading the offset 120 and nav bar button links are landing too high.

    Maybe there is something in the site that is conflicting with this Javascript?

    Sorry to bother you with this. We really gave it all we have.

    TIA!
    Lisa
    The reply is currently minimized Show
  • Accepted Answer

    Sunday, January 20 2019, 03:41 PM - #Permalink
    Hi Lisa,

    Please send me the site details by using the Site Details tab in your next comment so I can have a look.
    The reply is currently minimized Show
  • Accepted Answer

    Giora
    Giora
    Offline
    Sunday, January 20 2019, 03:54 PM - #Permalink
    Thanks Ivo!
    The site is https://www.intego-funds.com/dev/.
    The site details are below.
    If you need FTP, I'll ask Giora for the pw.
    The reply is currently minimized Show
  • Accepted Answer

    Giora
    Giora
    Offline
    Sunday, January 20 2019, 04:04 PM - #Permalink
    Pass is attached
    The reply is currently minimized Show
  • Accepted Answer

    Sunday, January 20 2019, 04:11 PM - #Permalink
    Hi Lisa,

    You cannot have smooth scroll (and offset) with your current setup (with these URLs).
    Here, have a look at this video that I recorded for you. It shows everything in details.
    The reply is currently minimized Show
  • Accepted Answer

    Giora
    Giora
    Offline
    Sunday, January 20 2019, 04:34 PM - #Permalink
    WOWOWOW!
    Such a simple fix.
    We're were chasing our tails!
    Thank you so so so very much!
    Lisa
    The reply is currently minimized Show
  • Accepted Answer

    Sunday, January 20 2019, 05:26 PM - #Permalink
    You are welcome Lisa :)
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, October 20 2022, 01:25 PM - #Permalink
    Ivo Valkov wrote:

    Hi Lisa,

    You cannot have smooth scroll (and offset) with your current setup (with these URLs).
    Here, have a look at this video that I recorded for you. It shows everything in details.


    Dear Ivo, This video shows that you can only have smooth scroll inside of the page there is #links, what about when you are in another page and you want to click form there back to a #section of other's page? can this happen ?
    The reply is currently minimized Show
  • Accepted Answer

    Friday, October 21 2022, 11:01 AM - #Permalink
    Hi Kostas,

    Nope, unfortunately it is not possible.
    The smooth scroll functionality works for links/anchors on the same page only.
    The reply is currently minimized Show
  • Accepted Answer

    Monday, October 24 2022, 12:04 PM - #Permalink
    Thanks you Ivo. For all.
    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, October 26 2022, 03:34 PM - #Permalink
    No worries, Kostas!
    The reply is currently minimized Show
Your Reply

Become an insider | Subscribe to our Newsletter
Subscribe to our mailing list and stay up-to-date with all our awesome releases, latest updates and amazing discount offers!