Skip to content

Commit

Permalink
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,6 @@ export function isPromise<T>(obj: any): obj is PromiseLike<T> {
}

export const Utils = {
getScrollParent(el: HTMLElement): HTMLElement {
const regex = /(auto|scroll)/;
while (el.parentNode) {
el = el.parentNode as HTMLElement;
const overflow = getComputedStyle(el, null).getPropertyValue('overflow') +
getComputedStyle(el, null).getPropertyValue('overflow-y') +
getComputedStyle(el, null).getPropertyValue('overflow-x');
if (regex.test(overflow)) {
return el;
}
}
return document.body;
},

scrollTo(element: HTMLElement, to: number, duration = 1000) {
function easeInOutQuad(t: number, b: number, c: number, d: number) {
t /= d / 2;
if (t < 1) {
return c / 2 * t * t + b;
}

t--;
return -c / 2 * ( t * ( t - 2 ) - 1) + b;
}
const start = element.scrollTop;
const change = to - start;
let currentTime = 0;
const increment = 20;

const animateScroll = () => {
currentTime += increment;
element.scrollTop = easeInOutQuad(currentTime, start, change, duration);
if (currentTime < duration) {
setTimeout(animateScroll, increment);
}
};
animateScroll();
},

toObservable<T>(val: T | Observable<T> | Promise<T>): Observable<T> {
const observable = val as Observable<T>;
if (observable && observable.subscribe && observable.forEach) {
Expand Down

0 comments on commit ba20f5e

Please sign in to comment.