[英]Setting Spinner Z-index in React
Hi I am trying to display a spinner on top of every component.您好,我正在尝试在每个组件的顶部显示一个微调器。 On spinner truthy, I reduce the opacity of the parent component.
在 spinner truthy 上,我降低了父组件的不透明度。 And trying to provide z-index for the spinner.
并尝试为微调器提供 z-index。 However, the z-index is not applied.
但是,不应用 z-index。 Please help me with the css. Thanks
请帮我css。谢谢
<div className={`${spinnerIsLoading ? 'parent-grey-out': ''}`}>{children}</>
.parent-grey-out{
opacity: 0.5 !important;
}
Now there is a child component where the spinner is loaded.现在有一个加载微调器的子组件。 I am using
useContext
to set the spinner true or false.我正在使用
useContext
将微调器设置为 true 或 false。
<div className={`spinner`}>
LOADING
</div>
.spinner{
display: none;
text-align: center;
position: absolute;
display: flex;
justify-content: center;
align-items: center;
width: 60px;
height: 60px;
z-index: 9999 !important;
left: 48%;
top: 45%;
}
.spinner:before{
content: "";
height: 60px;
width: 60px;
position: absolute;
top: 0;
left: 0;
border-radius: 50%;
background-color: transparent;
border: 5px solid #d8d8d8;
border-top: 5px solid #002569;
border-right: 5px solid #002569;
-webkit-animation: 1s linear infinite spin;
animation: 0.9s linear infinite spin;
z-index: 9999 !important;
}
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
Where is the spinner in tree?树上的旋转器在哪里?
If you want to display the spinner on top of everything, but still want to keep the spinner inside a component, you could take a look at React Portal如果您想在所有内容之上显示微调器,但仍想将微调器保留在组件内,您可以看看React Portal
React Portal i usually used for creating modals, but from what I understand from your question, that is what you more or less want to do. React Portal 我通常用于创建模式,但根据我从你的问题中了解到的情况,这或多或少是你想要做的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.