Skip to content

Commit

Permalink
Select Language hide after some scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
zalabhavy committed Jul 22, 2024
1 parent 20d5a40 commit 9dec226
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 16 additions & 2 deletions frontend/src/components/GoogleTranslate.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from "react";
import { useEffect, useState } from "react";
import "../styles/Translate.css";

declare global {
Expand All @@ -9,6 +9,8 @@ declare global {
}

const GoogleTranslate = () => {
const [isVisible, setIsVisible] = useState(true);

useEffect(() => {
window.googleTranslateInit = () => {
if (!window.google.translate.TranslateElement) {
Expand Down Expand Up @@ -39,9 +41,21 @@ const GoogleTranslate = () => {
if (window.google && window.google.translate) {
window.googleTranslateInit();
}

const handleScroll = () => {
setIsVisible(window.scrollY < 100); // Adjust the scroll amount as needed
};

window.addEventListener('scroll', handleScroll);

return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);

return <div id="google_element" className="google-translate-container"></div>;
return (
<div id="google_element" className={`google-translate-container ${isVisible ? '' : 'hidden'}`}></div>
);
};

export default GoogleTranslate;
4 changes: 4 additions & 0 deletions frontend/src/styles/Translate.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ font {
background: none !important;
box-shadow: none !important;
}

.google-translate-container.hidden {
display: none !important;
}

0 comments on commit 9dec226

Please sign in to comment.