Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
Added parameter blockPosition to be able to change block position of smooth scroll.
  • Loading branch information
AliUP committed Jul 21, 2020
1 parent 249e916 commit 642d270
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 642d270

Please sign in to comment.