xxxxxxxxxx
var element = document.querySelector("#post-container");
// smooth scroll to element and align it at the bottom
element.scrollIntoView({ behavior: 'smooth'});
xxxxxxxxxx
//get coordinates of element - gives us DOM RECT
//this is relative to current visible viewport
const sectionCoords = section.getBoundingClientRect();
//OLD WAY
//scrolling
//to fix this and make it relative to document
//we need to add current scroll to both of coordinates
//we need to pass an object
window.scrollTo({
left: s1coords.left + window.pageXOffset,
top: s1coords.top + window.pageYOffset,
behavior: "smooth",
});
//MODERN WAY
//take the element that we want to scroll to
section.scrollIntoView({ behavior: "smooth" });