Using anchors on dynamic title pages

Hey, I’m currently building a site on which several dynamic pages are included. On each of the item pages I want to use a button to scroll down to a contact section. It works without problems on the “normal” pages, however on the dynamic item pages I can’t connect the button to the anchor as I can’t choose the item page or the dynamic page in the link settings under “anchor”.

I tried with some basic velo code as well. It didn’t work.

$w("#button").onClick(() => {     
    // Replace "anchor" with the ID of the anchor element// that         you want to jump to
    const anchor = $w("#anchor");     
    anchor.scrollIntoView();
});

It gives me the following error message
Property ‘scrollIntoView’ does not exist on type ‘HiddenCollapsedElement’
even though the section is neither hidden nor collapsed.

Does anyone have a solution for this?
Thanks a lot!!

Hey!

The Velo Forum might be able to help best (https://community.wix.com/velo/forum) but while you’re here, I’ll see what I can do :slight_smile:

$w( “#anchor” ); should be the element you want to scroll to (such as a section, image etc.)

And in Velo, to scroll to an element, you’d use .scrollTo() instead of .scrollIntoView(). Here’s the API reference - scrollTo - Velo API Reference - Wix.com

Also make sure it’s contained within the onReady (There should only be 1 onReady on the page).

The code might look something like this:

$w.onReady(function () {
    $w("#button").onClick(() => {
        // Replace "anchor" with the ID of the anchor element// that         you want to jump to
        const anchor = $w("#anchor");
        anchor.scrollTo();
    });
});

Hope that helps.

Amazing Noah! Thanks for the advice, it works now!