scrollintoview safari code example

Example 1: javascript scrollintoview

var element = document.getElementById("box");

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

Example 2: scroll to top smooth safari

<!--Example of a button to scroll to top, Remember to use the same id on both 
	the button and the function -->
  <button id='myBtn' >
    Click me to go to top!
  </button>

<!-- When the user clicks on the button, scroll to the top of the document-->
  <script>
    document.querySelector('#myBtn').addEventListener('click', function(e) {
      e.preventDefault();
      document.querySelector('body').scrollIntoView({ behavior: 'smooth' });
    });
  </script>
<!--To make it work you need to add the link to the file.-->
  <script src="smoothscroll.js"></script>

<!--I leave you the link to the file on the side: https://raw.githubusercontent.com/iamdustan/smoothscroll/master/src/smoothscroll.js  -->

Example 3: scrollintoview

element.scrollIntoView();
element.scrollIntoView(alignToTop); // Boolean parameter
element.scrollIntoView(scrollIntoViewOptions); // Object parameter

Tags:

Css Example