我在网站上制作人工预加载器时出现问题。我需要它在一段时间后淡出,但我不知道如何让组件在 React 中淡出。我在那里创建了一个类.closed,opacity: 0但没有帮助。代码如下,感谢您的帮助!
const App = () => {
const [loading, setLoading] = useState(true);
useEffect(() => {
setTimeout(() => {
setLoading(false);
}, 5000);
});
const content = loading ? <Preloader/> : <h1>Hello world!</h1>
return (
<div className='app'>
{content}
</div>
);
}
您可以使用其中一个动画库,例如
'react-transition-group'. 以下是类似功能的示例: https ://codesandbox.io/s/thirsty-pasteur-m77l2vp00x?from-embed=&file=/index.js:165-189