Anyone figure out "scroll to" as part of workflow?

@kyanaloe There are several options. They all involve a bit of Javascript. You can use these in the custom javascript action.

The two that I landed on after much research are these:

OPTION 1:

let e = document.getElementById("submit-content");
        e.scrollIntoView({
          block: 'start',
          behavior: 'smooth',
          inline: 'start'
        });

OPTION 2

const node = document.getElementById("submit-content");
const yourHeight = 120; //This is how far down the page you need the element to scroll to. Relevant primarily if you have a sticky horizontal navigation/header.

node.scrollIntoView(true);

const scrolledY = window.scrollY;

if (scrolledY) {
  window.scroll(0, scrolledY - yourHeight);
}

Option 1 has smooth scrolling. Option 2 is a hard scroll, but option 2 apparently has more cross browser acceptance.

I’m using option 2 in my project.

4 Likes