Let Me Tink About It
Let Me Tink About It

Reputation: 16122

Demo for iron-scroll-target-behavior in Polymer 2.x

I need to direct the browser to scroll to the top of the page. I think iron-scroll-target-behavior might be a good choice. But I can't find any working demos.

Can anyone locate or point me to a working demo of the iron-scroll-target-behavior element?

Here is the element on webcomponents.org.

Upvotes: 1

Views: 133

Answers (1)

Let Me Tink About It
Let Me Tink About It

Reputation: 16122

Instead of scroll-target-behavior, I'm just using the platform and going with: scrollIntoView(). Documentation

example
const element = document.getElementById("box");

element.scrollIntoView();
element.scrollIntoView(false);
element.scrollIntoView({block: "end"});
element.scrollIntoView({behavior: "instant", block: "end", inline: "nearest"});

Or, to scroll to the top of the page:

document.body.scrollIntoView({
  behavior: "smooth",
  block: "top",
})

Upvotes: 0

Related Questions