1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| const AnimatedCard = ({ isVisible, position }) => { const animatedStyle = useMemo(() => ({ transform: `translate3d(${position.x}px, ${position.y}px, 0)`, opacity: isVisible ? 1 : 0, transition: 'transform 0.3s ease, opacity 0.3s ease', willChange: 'transform, opacity', contain: 'paint' }), [isVisible, position]); return <div style={animatedStyle}>Card Content</div>; };
const Modal = ({ children, isOpen }) => { const [mounted, setMounted] = useState(false); useEffect(() => { setMounted(true); return () => setMounted(false); }, []); if (!mounted) return null; return createPortal( <div className="modal-overlay" style={{ position: 'fixed', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: 'rgba(0,0,0,0.5)', display: isOpen ? 'flex' : 'none', alignItems: 'center', justifyContent: 'center', zIndex: 1000, willChange: 'opacity' // 合成层优化 }} > <div className="modal-content"> {children} </div> </div>, document.body ); };
|