Skip to content

Commit

Permalink
[Optional] Title Fade
Browse files Browse the repository at this point in the history
  • Loading branch information
15Dkatz committed Oct 19, 2022
1 parent 7266941 commit dd44412
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 10 deletions.
Binary file modified portfolio/.parcel-cache/data.mdb
Binary file not shown.
32 changes: 32 additions & 0 deletions portfolio/dist/index.61d3354a.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion portfolio/dist/index.61d3354a.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions portfolio/dist/index.975ef6c8.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion portfolio/dist/index.975ef6c8.js.map

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions portfolio/src/Title.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,36 @@ const TITLES = [
];

class Title extends Component {
state = { titleIndex: 0 };
state = { titleIndex: 0, fadeIn: true };

componentDidMount() {
this.timeout = setTimeout(() => this.setState({ fadeIn: false }), 2000);

this.animateTitles();
}

componentWillUnmount() {
clearInterval(this.titleInterval);
clearTimeout(this.timeout);
}

animateTitles = () => {
this.titleInterval = setInterval(() => {
const titleIndex = (this.state.titleIndex + 1) % TITLES.length;

this.setState({ titleIndex });
this.setState({ titleIndex, fadeIn: true });

this.timeout = setTimeout(() => this.setState({ fadeIn: false }), 2000);
}, 4000);
}

render() {
const { titleIndex } = this.state;
const { fadeIn, titleIndex } = this.state;

const title = TITLES[titleIndex];

return (
<p>I am {title}</p>
<p className={fadeIn ? 'title-fade-in' : 'title-fade-out'}>I am {title}</p>
)
}
}
Expand Down
22 changes: 22 additions & 0 deletions portfolio/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,25 @@ h1, h2, h3, h4, h5 {
height: 200px;
border-radius: 100px;
}

.title-fade-out {
opacity: 0;
animation-name: fade-out;
animation-duration: 2s;
}

.title-fade-in {
opacity: 100;
animation-name: fade-in;
animation-duration: 2s;
}

@keyframes fade-out {
from {opacity: 100}
to {opacity: 0}
}

@keyframes fade-in {
from {opacity: 0}
to {opacity: 100}
}

0 comments on commit dd44412

Please sign in to comment.