FoundKey/packages/client/src/directives/sticky-container.ts

16 lines
594 B
TypeScript
Raw Normal View History

2021-04-13 18:23:29 +00:00
import { Directive } from 'vue';
export default {
mounted(src) {
2021-04-13 18:23:29 +00:00
const header = src.children[0];
const body = src.children[1];
2021-04-13 18:34:56 +00:00
const currentStickyTop = getComputedStyle(src).getPropertyValue('--stickyTop') || '0px';
2021-07-19 04:00:29 +00:00
src.style.setProperty('--stickyTop', `calc(${currentStickyTop} + ${header.offsetHeight}px)`);
if (body) body.dataset.stickyContainerHeaderHeight = header.offsetHeight.toString();
2021-04-13 18:23:29 +00:00
header.style.setProperty('--stickyTop', currentStickyTop);
header.style.position = 'sticky';
header.style.top = 'var(--stickyTop)';
header.style.zIndex = '1';
},
} as Directive;