dwysokinski.me/src/libs/useSmoothScroll.js

19 lines
384 B
JavaScript
Raw Normal View History

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