From dea639d78f0caee50231d785ca9692afe6ff3d12 Mon Sep 17 00:00:00 2001 From: Shruti Gupta <202151151@iiitvadodara.ac.in> Date: Fri, 13 Oct 2023 23:58:12 +0530 Subject: [PATCH] scroll to top button added --- src/components/home/BackToTopButton.js | 39 ++++++++++++++++++++++++++ src/pages/index.js | 2 ++ 2 files changed, 41 insertions(+) create mode 100644 src/components/home/BackToTopButton.js diff --git a/src/components/home/BackToTopButton.js b/src/components/home/BackToTopButton.js new file mode 100644 index 00000000..205ea0cc --- /dev/null +++ b/src/components/home/BackToTopButton.js @@ -0,0 +1,39 @@ +import React from 'react'; +import { useEffect, useState } from 'react'; +import { ArrowUpIcon } from '@heroicons/react/outline' + +function BackToTopButton() { + const [backToTopButton, setBackToTopButton] = useState(false); + + useEffect(() =>{ + window.addEventListener("scroll", () => { + if(window.scrollY > 100){ + setBackToTopButton(true) + } else{ + setBackToTopButton(false) + } + }) + }, []) + + const scrollUp = () => { + window.scrollTo({ + top: 0, + behavior: "smooth" + }) + } + + return ( +