Files
swingmusic-extended/src/utils/useFocusElem.ts
T
2022-08-04 18:43:12 +03:00

24 lines
513 B
TypeScript

/**
* Scrolls a element into view.
* @param className The class to focus
* @param delay Delay in milliseconds
* @param pos Positioning of the focus element
*/
export default function focusElem(
className: string,
delay?: number,
pos?: any
) {
const dom = document.getElementsByClassName(className)[0];
setTimeout(() => {
if (dom) {
dom.scrollIntoView({
behavior: "smooth",
block: `${pos ?? "start"}` as any,
inline: "center",
});
}
}, delay | 300);
}