Skip to content

Commit

Permalink
Rename entry file
Browse files Browse the repository at this point in the history
  • Loading branch information
marlospomin committed May 2, 2020
1 parent b612a20 commit 9edefcf
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const defaultConfig = {
// Where to align the element
block: 'start',
// Animation method
behavior: 'smooth',
}

export default function(config = {}) {
// Push defaults into config object
config = { ...defaultConfig, ...config }
// Get the elements marked for smooth scrolling
const elements = document.querySelectorAll('[data-smoothie]')
// For each element get href value
Array.from(elements).forEach((element) => {
// Save the href value from each element
const link = element.getAttribute('href')
// Create the click events
element.addEventListener('click', (event) => {
// Prevent default behavior
event.preventDefault()
// Load proper hash in the url
history.pushState(null, null, link)
// Scroll into view the element
document.querySelector(link).scrollIntoView(config)
})
})
}

0 comments on commit 9edefcf

Please sign in to comment.