parent
cb13f66b3d
commit
804cbb8c56
|
After Width: | Height: | Size: 658 KiB |
|
After Width: | Height: | Size: 644 KiB |
@ -1,13 +1,27 @@
|
||||
import useResizeObserver from '@react-hook/resize-observer';
|
||||
import React from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export default function useSize(target: any) {
|
||||
const [size, setSize] = React.useState();
|
||||
const useResizeObserver = (ref: React.RefObject<HTMLElement>) => {
|
||||
const [size, setSize] = useState({ width: 0, height: 0 });
|
||||
|
||||
React.useLayoutEffect(() => {
|
||||
setSize(target.current?.getBoundingClientRect());
|
||||
}, [target]);
|
||||
useEffect(() => {
|
||||
const element = ref.current;
|
||||
if (!element) return;
|
||||
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
if (entries[0]) {
|
||||
const { width, height } = entries[0].contentRect;
|
||||
setSize({ width, height });
|
||||
}
|
||||
});
|
||||
|
||||
observer.observe(element);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
};
|
||||
}, [ref]);
|
||||
|
||||
useResizeObserver(target, (entry: any) => setSize(entry?.contentRect));
|
||||
return size;
|
||||
}
|
||||
};
|
||||
|
||||
export default useResizeObserver;
|
||||
|
||||
@ -1,39 +1,44 @@
|
||||
// import Img01 from '@/assets/images/img_01.png';
|
||||
import Img02 from '@/assets/images/img_02.png';
|
||||
|
||||
export default [
|
||||
{
|
||||
dataUrl:
|
||||
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
||||
height: 'auto',
|
||||
width: 'auto',
|
||||
// dataUrl:
|
||||
// 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
||||
dataUrl: Img02,
|
||||
height: 1024,
|
||||
width: 512,
|
||||
uid: 0,
|
||||
span: 12,
|
||||
loading: true,
|
||||
span: 24,
|
||||
loading: false,
|
||||
progress: 30
|
||||
},
|
||||
{
|
||||
dataUrl:
|
||||
'https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp',
|
||||
height: 'auto',
|
||||
width: 'auto',
|
||||
uid: 1,
|
||||
span: 12,
|
||||
progress: 15
|
||||
},
|
||||
{
|
||||
dataUrl:
|
||||
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
||||
height: 'auto',
|
||||
width: 'auto',
|
||||
uid: 3,
|
||||
span: 12,
|
||||
progress: 10
|
||||
},
|
||||
{
|
||||
dataUrl:
|
||||
'https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp',
|
||||
height: 'auto',
|
||||
width: 'auto',
|
||||
uid: 4,
|
||||
span: 12,
|
||||
progress: 15
|
||||
}
|
||||
// {
|
||||
// // dataUrl:
|
||||
// // 'https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp',
|
||||
// dataUrl: Img02,
|
||||
// height: 1024,
|
||||
// width: 512,
|
||||
// uid: 1,
|
||||
// span: 12,
|
||||
// progress: 15
|
||||
// }
|
||||
// {
|
||||
// dataUrl:
|
||||
// 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
||||
// height: 'auto',
|
||||
// width: 'auto',
|
||||
// uid: 3,
|
||||
// span: 12,
|
||||
// progress: 10
|
||||
// },
|
||||
// {
|
||||
// dataUrl:
|
||||
// 'https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp',
|
||||
// height: 'auto',
|
||||
// width: 'auto',
|
||||
// uid: 4,
|
||||
// span: 12,
|
||||
// progress: 15
|
||||
// }
|
||||
];
|
||||
|
||||
Loading…
Reference in new issue