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 "@styles/App.scss";
|
||||||
import Header from "@components/Header";
|
import Header from "@components/Header";
|
||||||
import About from "@sections/About";
|
import About from "@sections/About";
|
||||||
@@ -13,10 +13,31 @@ export default function App() {
|
|||||||
const skillsRef = useRef(null);
|
const skillsRef = useRef(null);
|
||||||
const projectsRef = 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(() => {
|
useEffect(() => {
|
||||||
const observer = new IntersectionObserver(
|
const observer = new IntersectionObserver(
|
||||||
(entries) => {
|
(entries) => {
|
||||||
entries.forEach((entry) => {
|
entries.forEach((entry) => {
|
||||||
|
if (isScrolling) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (entry.isIntersecting) {
|
if (entry.isIntersecting) {
|
||||||
window.location.hash = entry.target.id;
|
window.location.hash = entry.target.id;
|
||||||
entry.target.classList.add("active");
|
entry.target.classList.add("active");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import "@styles/Projects.scss";
|
import "@styles/Projects.scss";
|
||||||
import Badge from "@components/Badge";
|
import Badge from "@components/Badge";
|
||||||
import { BadgeType } from "@components/BadgeType";
|
import { BadgeType } from "@components/BadgeType";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
function Project({
|
function Project({
|
||||||
name,
|
name,
|
||||||
@@ -13,10 +14,16 @@ function Project({
|
|||||||
image?: string;
|
image?: string;
|
||||||
link: string;
|
link: string;
|
||||||
}) {
|
}) {
|
||||||
const imageUrl =
|
const [imageUrl, setImageUrl] = useState<string | undefined>(image);
|
||||||
image ||
|
|
||||||
"https://source.unsplash.com/random/500x400?javascript&sig=" +
|
useEffect(() => {
|
||||||
Math.random() * 1000;
|
if (!image) {
|
||||||
|
setImageUrl(
|
||||||
|
"https://source.unsplash.com/random/500x400?javascript&sig=" +
|
||||||
|
Math.random() * 1000
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [image]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user