diff --git a/src/ScrollToTopButton.jsx b/src/ScrollToTopButton.jsx index a386903..79211a0 100644 --- a/src/ScrollToTopButton.jsx +++ b/src/ScrollToTopButton.jsx @@ -1,43 +1,57 @@ import React, { useState, useEffect } from "react"; +import styled from "styled-components"; +import { FaArrowUp } from "react-icons/fa"; -const ScrollToTopButton = () => { +const GoToTop = () => { const [isVisible, setIsVisible] = useState(false); - const toggleVisibility = () => { - if (window.pageYOffset > 300) { - setIsVisible(true); - } else { - setIsVisible(false); - } - }; + useEffect(() => { + const handleScroll = () => { + const currentScrollY = window.scrollY; - const scrollToTop = () => { - window.scrollTo({ - top: 0, - behavior: "smooth", - }); - }; + setIsVisible(currentScrollY > 200); // Change 200 to your desired scroll distance + }; + + window.addEventListener("scroll", handleScroll); - useEffect(() => { - window.addEventListener("scroll", toggleVisibility); return () => { - window.removeEventListener("scroll", toggleVisibility); + window.removeEventListener("scroll", handleScroll); }; }, []); + const goToTop = () => { + window.scrollTo({ top: 0, left: 0, behavior: "smooth" }); + }; + return ( -