Skip to content

Instantly share code, notes, and snippets.

@ksmandersen
Created July 4, 2019 17:21
Show Gist options
  • Save ksmandersen/dc350576cef267a44ef67c63a3e2da92 to your computer and use it in GitHub Desktop.
Save ksmandersen/dc350576cef267a44ef67c63a3e2da92 to your computer and use it in GitHub Desktop.
export const scrollToElement = (id, position) => {
const element = document.getElementById(id);
if (element) {
element.scrollIntoView({
behavior: 'smooth',
block: position,
});
}
};
export const scrollToContact = (position = 'center') =>
scrollToElement('contact_form', position);
export const scrollToTop = () => {
window.scrollTo(0, 0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment