35 lines
993 B
TypeScript
35 lines
993 B
TypeScript
export namespace DOMTools {
|
|
export const fixHeight = (e: unknown, onlyGrow?: any) => {
|
|
if (e instanceof Event) {
|
|
e = e.target;
|
|
}
|
|
if (e instanceof HTMLElement) {
|
|
if (onlyGrow !== true) {
|
|
e.style.height = '0'; // reset
|
|
}
|
|
e.style.height = `${e.scrollHeight + 10}px`;
|
|
}
|
|
}
|
|
|
|
export const animate = (e: unknown, animationName: string) => {
|
|
if (e instanceof Event) {
|
|
e = e.target;
|
|
}
|
|
if (e instanceof HTMLElement) {
|
|
e.style.animationName = '';
|
|
e.style.animationName = animationName;
|
|
}
|
|
}
|
|
|
|
export const scrollDown = (e: unknown, smooth?: any) => {
|
|
if (e instanceof Event) {
|
|
e = e.target;
|
|
}
|
|
if (e instanceof HTMLElement) {
|
|
e.scrollTo({
|
|
top: e.scrollHeight,
|
|
behavior: smooth !== false ? 'smooth' : 'instant',
|
|
});
|
|
}
|
|
}
|
|
} |