dwysokinski.me/src/libs/useSmoothScroll.js

17 lines
380 B
JavaScript
Raw Normal View History

2021-01-17 08:31:50 +00:00
import isSmoothScrollSupported from '@utils/isSmoothScrollSupported';
const useSmoothScroll = () => {
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
};
};
export default useSmoothScroll;