Files
caszl-next/app/_components/BackToTop.tsx

34 lines
727 B
TypeScript
Raw Normal View History

2023-11-02 17:24:34 +08:00
"use client";
2023-11-06 17:27:50 +08:00
import backTop from "@/app/_assets/backtop.png";
2023-11-02 17:24:34 +08:00
import Image from "next/image";
2023-11-03 17:25:10 +08:00
import { useScroll } from "ahooks";
2023-11-02 17:24:34 +08:00
2023-11-03 17:25:10 +08:00
/**
*
* @constructor
*/
2023-11-02 17:24:34 +08:00
const BackToTop = () => {
2023-11-03 17:25:10 +08:00
const position = useScroll();
2023-11-02 17:24:34 +08:00
return (
2023-11-03 17:25:10 +08:00
<div
className={`fixed bottom-4 right-10 h-[50px] w-[50px] overflow-hidden`}
>
2023-11-02 17:24:34 +08:00
<Image
2023-11-03 17:25:10 +08:00
onClick={() => {
window.scroll({
top: 0,
behavior: "smooth",
});
}}
className={`${
(position?.top ?? 0) > 100 ? "top-0" : "top-full"
} absolute left-0 h-full w-full cursor-pointer transition-all`}
2023-11-02 17:24:34 +08:00
src={backTop}
alt={""}
/>
</div>
);
};
export default BackToTop;