Skip to content

Commit

Permalink
Merge pull request #8 from AliUP-sro/patch-1
Browse files Browse the repository at this point in the history
Add parameter blockPosition to be able to change block position of smooth scroll.
  • Loading branch information
freddydumont authored Jul 21, 2020
2 parents 249e916 + 642d270 commit 9a18aa5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/**
* Smooth scrolling onClick event handler
* @param {string} selector argument will be passed to `querySelector`, usually an HTML id
* @param {string} [blockPosition='start'] argument will be used to determine position where will be scrolled to (start, center, end, nearest)
* @returns {boolean} false if `document.querySelector` doesn't find a match, otherwise true
*/
const scrollTo = (selector) => {
const scrollTo = (selector, blockPosition = 'start') => {
const element = document.querySelector(selector);

if (element) {
element.scrollIntoView({
behavior: 'smooth',
block: 'start',
block: blockPosition,
});

return true;
Expand Down

0 comments on commit 9a18aa5

Please sign in to comment.