2021-01-17 08:31:50 +00:00
|
|
|
import isSmoothScrollSupported from '@utils/isSmoothScrollSupported';
|
2020-07-14 12:38:07 +00:00
|
|
|
|
2021-04-24 16:26:01 +00:00
|
|
|
const useSmoothScroll = () => {
|
2020-07-14 12:38:07 +00:00
|
|
|
return id => e => {
|
2021-10-18 05:58:05 +00:00
|
|
|
if (!isSmoothScrollSupported()) {
|
|
|
|
return;
|
2020-07-14 12:38:07 +00:00
|
|
|
}
|
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
|
|
|
};
|
|
|
|
};
|
2021-04-24 16:26:01 +00:00
|
|
|
|
|
|
|
export default useSmoothScroll;
|