dwysokinski.me/src/libs/useSmoothScroll.js

15 lines
338 B
JavaScript
Raw Normal View History

2021-01-17 08:31:50 +00:00
import isSmoothScrollSupported from '@utils/isSmoothScrollSupported';
export default () => {
return id => e => {
if (isSmoothScrollSupported()) {
2021-01-17 08:31:50 +00:00
e.preventDefault();
document.querySelector('#' + id).scrollIntoView({
behavior: 'smooth',
block: 'start',
inline: 'nearest',
});
}
2021-01-17 08:31:50 +00:00
};
};