From 192d169aa6ef9ac5b66e8ce7de8a2065ba543b50 Mon Sep 17 00:00:00 2001 From: ingawei Date: Wed, 28 Sep 2022 20:57:17 -0700 Subject: [PATCH] ugly --- web/components/scroll-to-top-button.tsx | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 web/components/scroll-to-top-button.tsx diff --git a/web/components/scroll-to-top-button.tsx b/web/components/scroll-to-top-button.tsx new file mode 100644 index 00000000..22661229 --- /dev/null +++ b/web/components/scroll-to-top-button.tsx @@ -0,0 +1,39 @@ +import { ArrowCircleUpIcon } from '@heroicons/react/solid' +import clsx from 'clsx' +import { useEffect, useState } from 'react' +import { Button } from './button' + +export function ScrollToTopButton(props: { className?: string }) { + const { className } = props + const [visible, setVisible] = useState(false) + + useEffect(() => { + window.addEventListener('scroll', () => { + if (window.scrollY > 400) { + console.log('button commence') + setVisible(true) + } else { + setVisible(false) + } + }) + }, []) + + const scrollToTop = () => { + window.scrollTo({ + top: 0, + behavior: 'smooth', + }) + } + + return ( + + ) +}