[英]remove css class after x seconds on popup close
I have a delete popup which works fine, but have added z-index on that, due to that it gets flickering effect.我有一个可以正常工作的删除弹出窗口,但是在上面添加了 z-index,因为它会产生闪烁效果。 below is working code下面是工作代码
<div className={modalOpen ? 'fullw content-holder has-scroll model-opened setHeaderZindex' : 'fullw content-holder has-scroll'}>
i want something like:我想要类似的东西:
<div className={modalOpen? 'fullw content-holder has-scroll model-opened setHeaderZindex: otherState? fullw content-holder has-scroll model-opened(which remove z-index class on setTimeout): 'fullw content-holder has-scroll'(default class)} </div>
I am trying to remove 'setHeaderZindex' using setTimeout.我正在尝试使用 setTimeout 删除“setHeaderZindex”。 sample video link demo video示例视频链接演示视频
You can use the useState
hook after setTimeout
您可以在setTimeout
之后使用useState
挂钩
export default function App() {
const [className, setClassName] = useState('fullw content-holder has-scroll model-opened')
setTimeout(() => {
setClassName('fullw content-holder has-scroll model-opened setHeaderZindex');
}, 2000)
return (
<div className="App">
<h1>Hello</h1>
<h1 className={className}>World</h1>
</div>
);
}
Try to solve problem with styled-components.尝试解决样式组件的问题。 The simple example of how it works.它是如何工作的简单示例。
const StyledDiv = styled.div`
${props => props.something ? 'display: flex;' : 'display: none;'}
`
return <StyledDiv something={modalOpen} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.