Skip to content

Commit a650652

Browse files
committed
Enhance AlertBanner hover interaction and animation
1 parent 1029421 commit a650652

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

@theme/components/Navbar/Navbar.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,32 @@ const alertBanner = {
1919
export function AlertBanner({ message, button, link, show }) {
2020
const { useTranslate } = useThemeHooks();
2121
const { translate } = useTranslate();
22+
const bannerRef = React.useRef(null);
23+
24+
React.useEffect(() => {
25+
const banner = bannerRef.current;
26+
if (!banner) return;
27+
28+
// Define the event handler
29+
const handleMouseEnter = () => {
30+
banner.classList.add('has-hover');
31+
};
32+
33+
// Attach the event listener
34+
banner.addEventListener('mouseenter', handleMouseEnter);
35+
36+
// Clean up the event listener on unmount
37+
return () => {
38+
banner.removeEventListener('mouseenter', handleMouseEnter);
39+
};
40+
}, []);
41+
2242
if (show) {
2343
return (
2444
<a
2545
href={link}
2646
target="_blank"
47+
ref={bannerRef}
2748
className="top-banner fixed-top web-banner"
2849
rel="noopener noreferrer"
2950
aria-label="Get Tickets for XRP Ledger Apex 2025 Event"

static/css/devportal2024-v1.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

styles/_top-banner.scss

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
font-family: "Work Sans";
99
z-index: 9999;
1010
cursor: pointer;
11+
1112
&:hover {
1213
text-decoration: none;
1314
color: $white;
@@ -34,7 +35,7 @@
3435
z-index: 0;
3536
transform: scaleX(0); // Start scaled down to 0
3637
transform-origin: left; // Scale from the left edge
37-
transition: transform 1.2s cubic-bezier(0.25, 0.8, 0.25, 1);
38+
transition: transform 1s cubic-bezier(0.25, 0.8, 0.25, 1);
3839
will-change: transform; // Hint for smoother animations
3940
}
4041

@@ -100,11 +101,13 @@
100101
}
101102

102103
.button-icon {
104+
transform-style: preserve-3d;
103105
aspect-ratio: 0.71;
104106
object-fit: contain;
105107
width: 12.5px; // Scaled down from 13.8px
106108
animation: none;
107-
109+
transform: rotateZ(0deg);
110+
transition: transform 0.5s ease-in-out; // Adjust duration as needed
108111
@media (max-width: 524px) {
109112
width: 9px; // Scaled down from 10px
110113
}
@@ -148,4 +151,16 @@
148151
.button-icon {
149152
animation: iconJitter 1s ease-in-out;
150153
animation-iteration-count: 1;
154+
}
155+
@keyframes iconReturn {
156+
from {
157+
transform: translate3d(0, 0, 0) scale3d(1, 1, 1) rotateZ(45deg) skew(0deg, 0deg);
158+
}
159+
to {
160+
transform: translate3d(0, 0, 0) scale3d(1, 1, 1) rotateZ(0deg) skew(0deg, 0deg);
161+
}
162+
}
163+
/* After the banner has been hovered once, on unhover run the reverse animation */
164+
.web-banner.has-hover:not(:hover) .button-icon {
165+
animation: iconReturn 1s ease-in-out forwards;
151166
}

0 commit comments

Comments
 (0)