feat: adiciona função do botão de ir para o topo

This commit is contained in:
Gabriel Gomes Fernandes 2023-01-20 18:36:44 -03:00
parent 7e8e4d89d8
commit 2b24ab7297

View File

@ -24,6 +24,20 @@ import vtexpowered from "../../assets/images/vtexpowered.svg";
import m3developed from "../../assets/images/m3developed.svg";
const Footer = () => {
const [visible, setVisible] = useState(false);
useEffect(() => {
const handleResize = () => {
if (window.pageYOffset > 100) {
setVisible(true);
} else {
setVisible(false);
}
};
window.addEventListener("scroll", handleResize);
return () => {
window.removeEventListener("scroll", handleResize);
};
}, []);
return (
<div>
<Newsletter />
@ -197,9 +211,11 @@ const Footer = () => {
</a>
</button>
<button className={styles["button-icon"]}>
<a href="#header">
<img src={gototop} alt="" className={styles["go-top-icon"]} />
</a>
{visible && (
<a href="#header">
<img src={gototop} alt="" className={styles["go-top-icon"]} />
</a>
)}
</button>
</div>
</div>