mirror of
https://github.com/DerTyp7/dertyp7.github.io.git
synced 2025-10-29 12:52:08 +01:00
Add scrolling functionality to App component
This commit is contained in:
23
src/App.tsx
23
src/App.tsx
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import "@styles/App.scss";
|
||||
import Header from "@components/Header";
|
||||
import About from "@sections/About";
|
||||
@@ -13,10 +13,31 @@ export default function App() {
|
||||
const skillsRef = useRef(null);
|
||||
const projectsRef = useRef(null);
|
||||
|
||||
const [isScrolling, setIsScrolling] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
setIsScrolling(true);
|
||||
|
||||
setTimeout(() => {
|
||||
setIsScrolling(false);
|
||||
}, 100);
|
||||
};
|
||||
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
entries.forEach((entry) => {
|
||||
if (isScrolling) {
|
||||
return;
|
||||
}
|
||||
if (entry.isIntersecting) {
|
||||
window.location.hash = entry.target.id;
|
||||
entry.target.classList.add("active");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import "@styles/Projects.scss";
|
||||
import Badge from "@components/Badge";
|
||||
import { BadgeType } from "@components/BadgeType";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
function Project({
|
||||
name,
|
||||
@@ -13,10 +14,16 @@ function Project({
|
||||
image?: string;
|
||||
link: string;
|
||||
}) {
|
||||
const imageUrl =
|
||||
image ||
|
||||
"https://source.unsplash.com/random/500x400?javascript&sig=" +
|
||||
Math.random() * 1000;
|
||||
const [imageUrl, setImageUrl] = useState<string | undefined>(image);
|
||||
|
||||
useEffect(() => {
|
||||
if (!image) {
|
||||
setImageUrl(
|
||||
"https://source.unsplash.com/random/500x400?javascript&sig=" +
|
||||
Math.random() * 1000
|
||||
);
|
||||
}
|
||||
}, [image]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user