Skip to content

Commit 9a18aa5

Browse files
authored
Merge pull request #8 from AliUP-sro/patch-1
Add parameter blockPosition to be able to change block position of smooth scroll.
2 parents 249e916 + 642d270 commit 9a18aa5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
/**
22
* Smooth scrolling onClick event handler
33
* @param {string} selector argument will be passed to `querySelector`, usually an HTML id
4+
* @param {string} [blockPosition='start'] argument will be used to determine position where will be scrolled to (start, center, end, nearest)
45
* @returns {boolean} false if `document.querySelector` doesn't find a match, otherwise true
56
*/
6-
const scrollTo = (selector) => {
7+
const scrollTo = (selector, blockPosition = 'start') => {
78
const element = document.querySelector(selector);
89

910
if (element) {
1011
element.scrollIntoView({
1112
behavior: 'smooth',
12-
block: 'start',
13+
block: blockPosition,
1314
});
1415

1516
return true;

0 commit comments

Comments
 (0)