Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
updateScrollPoistion() {
const container = this.menuBodyContainerRef.current;
let activeItem = container.querySelector(`.${this.addPrefix('item-focus')}`);
if (!activeItem) {
activeItem = container.querySelector(`.${this.addPrefix('item-active')}`);
}
if (!activeItem) {
return;
}
const position = getPosition(activeItem, container);
const sTop = scrollTop(container);
const sHeight = getHeight(container);
if (sTop > position.top) {
scrollTop(container, Math.max(0, position.top - 20));
} else if (position.top > sTop + sHeight) {
scrollTop(container, Math.max(0, position.top - sHeight + 32));
}
}
this.menus.forEach(menu => {
if (!menu) {
return;
}
let activeItem = menu.querySelector(`.${this.addPrefix('item-focus')}`);
if (!activeItem) {
activeItem = menu.querySelector(`.${this.addPrefix('item-active')}`);
}
if (activeItem) {
const position = getPosition(activeItem, menu);
scrollTop(menu, position.top);
}
});
}
Object.entries(time).forEach((item: any) => {
const container: Element = this.container[item[0]];
const node = container.querySelector(`[data-key="${item[0]}-${item[1]}"]`);
if (node && container) {
const { top } = getPosition(node, container);
scrollTopAnimation(this.container[item[0]], top, scrollTop(this.container[item[0]]) !== 0);
}
});
};
handleBodyScroll = (event: SyntheticTouchEvent<*>) => {
if (event.target !== this.tableBody) {
return;
}
let left = scrollLeft(event.target);
let top = scrollTop(event.target);
if (top === 0 && left === 0) {
return;
}
this._listenWheel(left, top);
scrollLeft(event.target, 0);
scrollTop(event.target, 0);
};
export default function scrollTopAnimation(
target: Element,
nextTop: number,
animation = true,
callback?: (top: number) => void
) {
let top = scrollTop(target);
const step = () => {
scrollTop(target, top > nextTop ? nextTop : top);
if (top <= nextTop) {
requestAnimationFramePolyfill(step);
}
callback?.(top);
top += 20;
};
if (animation) {
requestAnimationFramePolyfill(step);
} else {
scrollTop(target, nextTop);
}
}
animation = true,
callback?: (top: number) => void
) {
let top = scrollTop(target);
const step = () => {
scrollTop(target, top > nextTop ? nextTop : top);
if (top <= nextTop) {
requestAnimationFramePolyfill(step);
}
callback?.(top);
top += 20;
};
if (animation) {
requestAnimationFramePolyfill(step);
} else {
scrollTop(target, nextTop);
}
}
handleWindowScroll() {
if (scrollTop(window) > 30) {
this.setState({
overflow: true
});
return;
}
this.setState({
overflow: false
});
},
render() {
getContainerDimensions(containerNode) {
let width, height, scroll;
if (containerNode.tagName === 'BODY') {
width = window.innerWidth;
height = window.innerHeight;
scroll = scrollTop(ownerDocument(containerNode).documentElement) || scrollTop(containerNode);
} else {
({ width, height } = getOffset(containerNode));
scroll = scrollTop(containerNode);
}
return { width, height, scroll };
},