polymerpolymer-2.xdemoiron-elements

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.


Solution

  • 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",
    })