Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon Keiver 1 post 71 karma points
    Dec 01, 2020 @ 12:32
    Simon Keiver
    0

    Anchor points - noob question

    Hi End-user here not a developer so I'm fairly ignorant when it comes to coding.

    Problem - single standard page with very long text, I want to add an anchor point low down the page that can be linked to be clicking on a 'querystring' (I think?) I see from previous posts/tutorials of how to add an anchor, but I do not seem to have an anchor tool as the video content makers did, could be my Umbraco version? (7.15.1)

    Can anyone please help me create this anchor point?

    Thank you Simon

  • Mark Pickard 23 posts 116 karma points
    Dec 09, 2020 @ 10:18
    Mark Pickard
    0

    Hi Simon,

    So on my Umbraco site I have a smooth scroll anchor feature. I am adding this to the current page (I am using Igloo theme and adding Grid>Code then inserting the below code which allows code to be added anywhere on the page. Without Igloo you will need to see how to add this like adding the JS directly into your template)

    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script type="text/javascript">
    $("a[href^='#']").click(function(e) {
        e.preventDefault();
        var position = $($(this).attr("href")).offset().top;
    $("body, html").animate({
            scrollTop: position
        } ,1000);
    });
    </script>
    

    I then use this as the link (href) on the button eg: "Take me to the anchor"

    #anchor

    <a href="#anchor">Take me to the anchor</a>
    

    I then insert an empty div right above the content I want to anchor to:

    <div id="anchor"></div>
    

    The javascript above is purely for a smooth scroll effect when you click the button it smooth scrolls down the page till it reaches your content. If you don't want the scroll and it just jumps then remove the JS and it will do a basic jump.

    Hope that helps in some way.

Please Sign in or register to post replies

Write your reply to:

Draft