From 71128aee002b6f7ed8f910612d73d9dfcab9ed0e Mon Sep 17 00:00:00 2001
From: Tben <52448020+BenjaminToby@users.noreply.github.com>
Date: Sat, 4 Jun 2022 08:26:53 +0100
Subject: [PATCH] updates
---
components/actions/TextShuffler.jsx | 156 ++++++++++++++++++-----
layouts/general_layout/GeneralHeader.jsx | 20 ++-
layouts/general_layout/GeneralLayout.jsx | 23 ++--
pages/_document.js | 1 +
pages/about.jsx | 4 +-
pages/contact.jsx | 4 +-
pages/index.jsx | 4 +-
pages/work.jsx | 4 +-
styles/main.css | 5 +-
9 files changed, 165 insertions(+), 56 deletions(-)
diff --git a/components/actions/TextShuffler.jsx b/components/actions/TextShuffler.jsx
index 97f7c3b..e5f9a38 100644
--- a/components/actions/TextShuffler.jsx
+++ b/components/actions/TextShuffler.jsx
@@ -4,12 +4,14 @@ import { gsap } from "gsap";
let timer = 0;
let keyNum = 0;
let textTimeout;
+let textInterval;
// let chars = ("abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+=-;.,/?><][}{:`~").split("");
+let interval = 200;
const TextShuffler = ({ textInput, delay }) => {
- let [text, setText] = useState(textInput);
- let [refresh, setRefresh] = useState(0);
+ // let [text, setText] = useState(textInput);
+ // let [refresh, setRefresh] = useState(0);
let [readyState, setReadyState] = useState(false);
const spanRef = React.useRef();
@@ -17,25 +19,13 @@ const TextShuffler = ({ textInput, delay }) => {
useEffect(() => {
const spanObserver = new IntersectionObserver((entries, observer) => {
if (entries[0].isIntersecting) {
- requestAnimationFrame(() => {
- if (delay) {
- setTimeout(() => {
- gsap.to(spanRef.current, {
- opacity: 1,
- duration: 2
- });
-
- setReadyState(true);
- }, delay);
- } else {
- gsap.to(spanRef.current, {
- opacity: 1,
- duration: 2
- });
-
+ if (delay) {
+ setTimeout(() => {
setReadyState(true);
- }
- })
+ }, delay);
+ } else {
+ setReadyState(true);
+ }
observer.unobserve(spanRef.current)
}
@@ -47,25 +37,129 @@ const TextShuffler = ({ textInput, delay }) => {
spanObserver.observe(spanRef.current)
}, [])
+ // useEffect(() => {
+ // if (!readyState) return;
+
+ // requestAnimationFrame(() => {
+ // textTimeout = setTimeout(() => {
+ // if (timer === 7) {
+ // setText(textInput);
+ // return window.clearTimeout(textTimeout);
+ // };
+
+ // setRefresh(prev => prev + 1);
+ // timer++
+ // }, 300);
+ // })
+ // }, [refresh, readyState])
+
useEffect(() => {
if (!readyState) return;
- requestAnimationFrame(() => {
- textTimeout = setTimeout(() => {
- if (timer === 7) {
- setText(textInput);
- return window.clearTimeout(textTimeout);
- };
- setRefresh(prev => prev + 1);
- timer++
- }, 300);
+
+ let chars = textInput.split("");
+
+
+
+ let charsSpans = chars.map(char => `${char}`)
+
+ spanRef.current.innerHTML = charsSpans.join("");
+
+ gsap.to(spanRef.current, {
+ opacity: 1,
+ duration: 1
+ });
+
+ let textSpans = spanRef.current.querySelectorAll("span");
+
+ // textInterval = setInterval(() => {
+ // if (timer >= 600) {
+ // window.clearInterval(textInterval);
+
+ // requestAnimationFrame(() => {
+ // textSpans.forEach(span => {
+ // // gsap.killTweensOf(span, "opacity");
+
+ // gsap.to(span, {
+ // opacity: 1,
+ // duration: Math.random(),
+ // delay: Math.random()
+ // })
+ // })
+ // })
+
+ // return;
+ // }
+
+ // requestAnimationFrame(() => {
+ // textSpans.forEach(span => {
+ // gsap.to(span, {
+ // opacity: 1,
+ // duration: Math.random() * 2,
+ // delay: Math.random() * 1.5
+ // })
+ // })
+
+ // // textSpans.forEach(span => {
+ // // gsap.to(span, {
+ // // opacity: 0,
+ // // duration: Math.random() * 2,
+ // // delay: Math.random() * 1.5
+ // // })
+ // // })
+
+ // // gsap.to(spanRef.current, {
+ // // opacity: 0,
+ // // duration: 2
+ // // });
+
+ // timer += interval;
+ // })
+
+ // }, interval)
+
+ requestAnimationFrame(() => {
+ // let charsSpans = chars.map(char => `${char}`)
+
+ // spanRef.current.innerHTML = charsSpans.join("");
+
+ // let textSpans = spanRef.current.querySelectorAll("span");
+
+ textSpans.forEach(span => {
+ gsap.to(span, {
+ opacity: 1,
+ duration: Math.random() * 1.5,
+ })
+ })
+
+ textSpans.forEach(span => {
+ gsap.killTweensOf(span, "opacity");
+ gsap.to(span, {
+ opacity: 0,
+ duration: Math.random() * 1.5,
+ delay: Math.random() * 0.5
+ })
+ })
+
+ textSpans.forEach(span => {
+ gsap.killTweensOf(span, "opacity");
+
+ gsap.to(span, {
+ opacity: 1,
+ duration: Math.random() * 1.5,
+ delay: Math.random()
+ })
+ })
})
- }, [refresh])
+
+
+ }, [readyState])
return (
- { text.split("").map(char => { char }) }
+ {/* { text.split("").map(char => { char }) } */ }
+ { textInput }
)
}
diff --git a/layouts/general_layout/GeneralHeader.jsx b/layouts/general_layout/GeneralHeader.jsx
index 1c51b3c..50be4e7 100644
--- a/layouts/general_layout/GeneralHeader.jsx
+++ b/layouts/general_layout/GeneralHeader.jsx
@@ -1,15 +1,23 @@
import React from 'react'
+import { useRouter } from 'next/router';
const GeneralHeader = () => {
+ const router = useRouter();
+
+ function pushRouter(e) {
+ let url = e.target.dataset.href;
+ router.push(url);
+ }
+
return (
Tben.me
+ { pushRouter("/") } }>Tben.me