I must display a loader and blur the complete background on button click and after a response from fetch this loader should not be displayed and the background should return to normal. Below is the code that I have tried but it does not work correctly. It blurs even the loader and the page remains blur even after the response.
.no_spinner_display {
display: none !important;
}
.body_blur {
filter: blur(3px);
}
.loader_parent {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
margin: auto;
}
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite; /* Safari */
animation: spin 2s linear infinite;
}
/* Safari */
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<body>
<header></header>
<table class="my_table">
<thead>
<tr>
<th>NAME</th>
<th>AGE</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
<div class="loader_parent no_spinner_display" id="loader_parent">
<div class="loader" id="loader"></div>
</div>
<tr>
<td>Jack</td>
<td>20</td>
<td>15</td>
<td>Jill</td>
<td>19</td>
<td>10</td>
<td>John</td>
<td>21</td>
<td>30</td>
</tr>
</tbody>
</table>
<button>Submit</button>
<footer></footer>
</body>
I have added the loader
element at that position because I want it to be displayed in the middle of the screen.
let myClass = document.querySelectorAll('.myClass');
myClass.forEach((ele) => {
ele.addEventListener('change', () => {
var body = document.getElementsByTagName("BODY")[0];
var loader = document.getElementById('loader_parent');
body.classList.add('body_blur');
loader.classList.remove('no_spinner_display', 'body_blur');
fetchData(ele.value);
});
});
fetchData = async (ele) => {
if (response.success) {
var body = document.getElementsByTagName("BODY")[0];
var loader = document.getElementById('loader_parent');
body.classList.remove('body_blur');
loader.classList.add('no_spinner_display');
}
}
body > *:not(#loader) {
filter: blur(3px);
}
// This code when added in css blurs all except loader but I want to add this code in a class if I want the desired functionality.
What should I change in order for the code to work as per my requirement?
Can I add css like this?
.body_blur {
body > *:not(#loader) {
filter: blur(3px);
}
}