Jump to content

"Get in Touch button" auto scroll to contact form

Go to solution Solved by tuanphan,

Recommended Posts

Posted

Hi there, 

I have two "Get in Touch" Buttons on my site https://www.greenhousecounselling.co.uk/ 

It currently is set up as hyperlink to send a email, however I would love if instead it could autoscroll someone down to  the "get in touch" block of my website. image.thumb.png.7fe5b5a3189404cf223b2acebe446424.png

Is there any way to make this possible? Or am I best to set up a secondary hidden page to redirect them to with the contact form. I'm just having issues with the "get in touch" buttons not linking out to anywhere. 

 

Thank you in advance! 🙂

B

Posted

in your button add the section id like that,
#section-one
here section-one will be replaced according to your button id . 

For  smooth scrolling you can add below code but it is optional.

add this code into pages > web tools > code injeciton > footer:

<script>
document.addEventListener("DOMContentLoaded", function () {
    const links = document.querySelectorAll('a[href^="#"]'); // Select all anchor links

    links.forEach(link => {
        link.addEventListener("click", function (event) {
            event.preventDefault(); // Prevent default jump

            const targetId = this.getAttribute("href").substring(1); // Get the ID
            const targetElement = document.getElementById(targetId);

            if (targetElement) {
                targetElement.scrollIntoView({
                    behavior: "smooth", // Smooth scrolling
                    block: "start" // Scroll to the top of the section
                });
            }
        });
    });
});
</script>

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.