mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-25 00:12:08 +08:00
fix animation frame resize observer
This commit is contained in:
@@ -70,8 +70,8 @@ export default {
|
||||
const isScrollable = ref(false);
|
||||
const { arrived } = useAnimationFrameScroll(scrollContainer);
|
||||
|
||||
useAnimationFrameResizeObserver(scrollContainer, () => {
|
||||
isScrollable.value = scrollContainer.value.scrollWidth >= scrollContainer.value.clientWidth;
|
||||
useAnimationFrameResizeObserver(scrollContainer, ({ clientSize, scrollSize }) => {
|
||||
isScrollable.value = scrollSize.width >= clientSize.width + 1;
|
||||
});
|
||||
|
||||
const scrolledLeft = computed(() => !isScrollable.value || arrived.left);
|
||||
|
||||
@@ -2,16 +2,30 @@ import { useAnimationFrame } from "./animationFrame";
|
||||
import { unref } from "vue";
|
||||
|
||||
export function useAnimationFrameResizeObserver(element, callback) {
|
||||
var lastSize = { width: 0, height: 0 };
|
||||
var clientSize = { width: 0, height: 0 };
|
||||
var scrollSize = { width: 0, height: 0 };
|
||||
|
||||
const isSameSize = (a, b) => {
|
||||
return a.width === b.width && a.height === b.height;
|
||||
};
|
||||
|
||||
const { stop } = useAnimationFrame(() => {
|
||||
const el = unref(element);
|
||||
const width = el.offsetWidth;
|
||||
const height = el.offsetHeight;
|
||||
|
||||
if (lastSize.width !== width || lastSize.height !== height) {
|
||||
callback({ width, height }, lastSize);
|
||||
lastSize = { width, height };
|
||||
const newClientSize = {
|
||||
width: el.clientWidth,
|
||||
height: el.clientHeight,
|
||||
};
|
||||
|
||||
const newScrollSize = {
|
||||
width: el.scrollWidth,
|
||||
height: el.scrollHeight,
|
||||
};
|
||||
|
||||
if (!isSameSize(clientSize, newClientSize) || !isSameSize(scrollSize, newScrollSize)) {
|
||||
callback({ clientSize: newClientSize, scrollSize: newScrollSize }, { clientSize, scrollSize });
|
||||
clientSize = newClientSize;
|
||||
scrollSize = newScrollSize;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user