Reputation: 21
For my website, when a button is clicked, the screen blurs. I am now trying to add a loading animation of a spinning circle on top of that blur when the button is pressed, however, I'm running into a lot of issues. When I tried to also have the button click have "isActive" and then make the loader class div when it isActive, the entire website crashed.
js file code:
import React from "react";
import "./App.scss";
class App extends React.Component {
state = { fadingOut: false }
fadeOut = () => this.setState({fadingOut: true});
render() {
return (
<div className="App" style={this.state.fadingOut ? {filter:
'blur(0.35vw)'} : undefined }
>
<div className="top-bar">
<div className="title">
.datapoems
</div>
<img className="logo" src="./logo.png"/>
</div>
<div className="container">
<div className="sloganLineOne">Poem Theme</div>
<div className="sloganLineTwo">Detector</div>
<textarea className="inputField" placeholder="Please Enter
Your Poem Here..."></textarea>
<button className="button" onClick=
{this.fadeOut}>Enter</button>
<img className="leftTriangle"
src="./leftSideTriangle.png"/>
<img className="rightTriangle"
src="./rightSideTriangle.png"/>
</div>
</div>
);
}
}
export default App;
scss loader code:
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid blue;
border-bottom: 16px solid blue;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
Upvotes: 0
Views: 609
Reputation: 676
I took your code and modified it just a little bit to achieve your desired result (based on what I understood from your question).
class App extends Component {
state = { fadingOut: false };
fadeOut = () => this.setState({ fadingOut: true });
render() {
const contentStyle = this.state.fadingOut
? { filter: "blur(0.35vw)" }
: undefined;
const loadingIndicator = this.state.fadingOut ? (
<div style={loaderStyle}>-- Loading icon --</div>
) : null;
return (
<div className="App" style={{ position: "relative" }}>
<div style={contentStyle}>
<div className="top-bar">
<div className="title">.datapoems</div>
<img className="logo" src="./logo.png" />
</div>
<div className="container">
<div className="sloganLineOne">Poem Theme</div>
<div className="sloganLineTwo">Detector</div>
<textarea
className="inputField"
placeholder="Please Enter Your Poem Here..."
/>
<button className="button" onClick={this.fadeOut}>
Enter
</button>
<img className="leftTriangle" src="./leftSideTriangle.png" />
<img className="rightTriangle" src="./rightSideTriangle.png" />
</div>
</div>
{loadingIndicator}
</div>
);
}
}
const loaderStyle = {
position: "absolute", // or position: "fixed"
top: 0,
bottom: 0,
left: 0,
right: 0,
display: "flex",
justifyContent: "center",
alignItems: "center"
};
https://codesandbox.io/s/react-example-353dg
Upvotes: 1