mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-12-20 01:28:09 +09:00
e548abb13f
* pick form
* pick message
* pick room
* fix lint
* fix scroll?
* fix scroll.ts
* fix directives/sticky-container
* update global/sticky-container.vue
* fix, 🎨
* test.1
67 lines
1.4 KiB
Vue
67 lines
1.4 KiB
Vue
<template>
|
|
<div ref="rootEl">
|
|
<slot name="header"></slot>
|
|
<div ref="bodyEl" :data-sticky-container-header-height="headerHeight">
|
|
<slot></slot>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { onMounted, onUnmounted } from 'vue';
|
|
|
|
const props = withDefaults(defineProps<{
|
|
autoSticky?: boolean;
|
|
}>(), {
|
|
autoSticky: false,
|
|
});
|
|
|
|
const rootEl = $ref<HTMLElement>();
|
|
const bodyEl = $ref<HTMLElement>();
|
|
|
|
let headerHeight = $ref<string | undefined>();
|
|
|
|
const calc = () => {
|
|
const currentStickyTop = getComputedStyle(rootEl).getPropertyValue('--stickyTop') || '0px';
|
|
|
|
const header = rootEl.children[0] as HTMLElement;
|
|
if (header === bodyEl) {
|
|
bodyEl.style.setProperty('--stickyTop', currentStickyTop);
|
|
} else {
|
|
bodyEl.style.setProperty('--stickyTop', `calc(${currentStickyTop} + ${header.offsetHeight}px)`);
|
|
headerHeight = header.offsetHeight.toString();
|
|
|
|
if (props.autoSticky) {
|
|
header.style.setProperty('--stickyTop', currentStickyTop);
|
|
header.style.position = 'sticky';
|
|
header.style.top = 'var(--stickyTop)';
|
|
header.style.zIndex = '1';
|
|
}
|
|
}
|
|
};
|
|
|
|
const observer = new MutationObserver(() => {
|
|
window.setTimeout(() => {
|
|
calc();
|
|
}, 100);
|
|
});
|
|
|
|
onMounted(() => {
|
|
calc();
|
|
|
|
observer.observe(rootEl, {
|
|
attributes: false,
|
|
childList: true,
|
|
subtree: false,
|
|
});
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
observer.disconnect();
|
|
});
|
|
</script>
|
|
|
|
<style lang="scss" module>
|
|
|
|
</style>
|