Skip to content

Commit 472b745

Browse files
Adding opacity transition to hero dynamic titles
1 parent e269f2c commit 472b745

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

components/Hero.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@ export default function Hero({
1414
titleClass,
1515
}) {
1616
const [titleIndex, setTitleIndex] = useState(0);
17-
const handleTitleIndex = () =>
17+
const handleTitleIndex = () => {
1818
setTitleIndex(titleIndex >= dynamicTitles.length - 1 ? 0 : titleIndex + 1);
19+
};
1920

2021
useEffect(() => {
21-
setTimeout(handleTitleIndex, 1350);
22+
const dynamicTitleEl = document.getElementById('dynamicTitle');
23+
if (dynamicTitleEl.style.opacity === '1') {
24+
dynamicTitleEl.style.opacity = '0';
25+
} else {
26+
dynamicTitleEl.style.opacity = '1';
27+
}
2228
}, [titleIndex]);
2329

30+
setTimeout(handleTitleIndex, 1750);
31+
2432
return (
2533
<div
2634
className={`${styles.header} ${customClass ? styles[customClass] : ''}`}
@@ -39,7 +47,9 @@ export default function Hero({
3947
<div className={styles.header__content__upper}>
4048
<h1 className={titleClass ? `${styles[titleClass]}` : ''}>
4149
{title}
42-
{dynamicTitles && <span> {dynamicTitles[titleIndex]}</span>}
50+
{dynamicTitles && (
51+
<span id="dynamicTitle"> {dynamicTitles[titleIndex]}</span>
52+
)}
4353
</h1>
4454
</div>
4555
<div className={styles.header__content__bottom}>

styles/Hero.module.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
font-style: italic;
2828
font-weight: bold;
2929
line-height: 3.5rem;
30+
opacity: 1;
31+
@include transition(opacity 1.55s ease-in-out);
3032
@include desktop {
3133
font-size: 4.5rem;
3234
line-height: 5rem;

utils/hero-options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const heroOptions = {
33
imgBg: '/images/home-bg.png',
44
imgAlt: 'Homepage',
55
title: 'Web Dev Path is about',
6-
dynamicTitles: ['community', 'learning', 'growth'],
6+
dynamicTitles: ['community', 'learning', 'growth', 'teamwork'],
77
content:
88
'We help junior tech professionals, such as developers and designers, to grow.',
99
},

0 commit comments

Comments
 (0)