From 3195cfd39fc80234d5ec247c44351a8e1c18d8b8 Mon Sep 17 00:00:00 2001 From: painterpuppets Date: Thu, 9 May 2024 10:33:25 +0800 Subject: [PATCH] styling: change `absolute` position to `fixed` --- src/pages/index.tsx | 114 +++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 45 deletions(-) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index f73dee4..ffbd64f 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import Image from "next/image"; import clsx from "clsx"; import PixelArrow from "./pixelarticons_arrow.svg"; @@ -22,6 +22,30 @@ import RainbowImage from "./rainbow.png"; import PhoneImage from "./phone.png"; import Head from "next/head"; +function getWindowDimensions() { + const { innerWidth: width, innerHeight: height } = window; + return { + width, + height + }; +} + +function useWindowDimensions() { + const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions()); + + useEffect(() => { + function handleResize() { + setWindowDimensions(getWindowDimensions()); + } + + window.addEventListener('resize', handleResize); + return () => window.removeEventListener('resize', handleResize); + }, []); + + return windowDimensions; +} + + enum Page { Home, Nashville, @@ -29,21 +53,21 @@ enum Page { } const HomeBackground: React.FC = () => ( -
-
-
-
+
+
+
+
- - - + + + rainbow picture ( width={140} src={RainbowImage.src} alt="rainbow picture" - className="absolute top-1/2 left-1/2 transform translate-x-[90px] -translate-y-[220px] rotate-[170deg]" + className="fixed top-1/2 left-1/2 transform translate-x-[90px] -translate-y-[220px] rotate-[170deg]" /> ( width={448} src={BtcImage.src} alt="btc picture" - className="absolute h-[550px] w-[448px] object-cover top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-[60%]" + className="fixed h-[550px] w-[448px] object-cover top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-[60%]" /> - - - - + + + + rgb++ picture ( width={150} src={GreenGuy.src} alt="green guy picture" - className="absolute top-1/2 left-1/2 transform translate-x-14 translate-y-1" + className="fixed top-1/2 left-1/2 transform translate-x-14 translate-y-1" /> ( width={55} src={PhoneImage.src} alt="mobile phone picture" - className="absolute top-1/2 left-1/2 transform -translate-x-[156px] translate-y-[20px]" + className="fixed top-1/2 left-1/2 transform -translate-x-[156px] translate-y-[20px]" /> ( width={55} src={PhoneImage.src} alt="mobile phone picture" - className="absolute top-1/2 left-1/2 transform -translate-x-[202px] translate-y-[69px]" + className="fixed top-1/2 left-1/2 transform -translate-x-[202px] translate-y-[69px]" /> ( width={107} src={PhoneImage.src} alt="mobile phone picture" - className="absolute top-1/2 left-1/2 transform -translate-x-[240px]" + className="fixed top-1/2 left-1/2 transform -translate-x-[240px]" />
@@ -114,7 +138,7 @@ const HomeBackground: React.FC = () => ( width={300} src={BlueGuy.src} alt="blue guy" - className="absolute h-[24vh] w-[32vh] bottom-0 left-1/2 transform -translate-x-[100%]" + className="fixed h-[24vh] w-[32vh] bottom-0 left-1/2 transform -translate-x-[100%]" /> ( width={300} src={RedGuy.src} alt="red guy" - className="absolute h-[24vh] w-[32vh] bottom-0 left-1/2" + className="fixed h-[24vh] w-[32vh] bottom-0 left-1/2" /> ( width={300} src={DancingCyanGuy.src} alt="dancing cyan guy.gif" - className="absolute h-[40vh] w-[30vh] -bottom-[8vh] left-1/2 transform -translate-x-1/2" + className="fixed h-[40vh] w-[30vh] -bottom-[8vh] left-1/2 transform -translate-x-1/2" />
@@ -140,12 +164,12 @@ const HomePage: React.FC = () => (
-
+
Friends of Bitcoin
-
+
= ({ }) => (
-
+