diff --git a/src/App.tsx b/src/App.tsx index 352935a..b07079c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,6 +3,26 @@ import "./App.css"; function App() { const [count, setCount] = useState(0); + + const callback = function (entries: IntersectionObserverEntry[]) { + entries.forEach((entry) => { + console.log(entry); + if (entry.isIntersecting) { + entry.target.classList.add("animate-fadeIn"); + } else { + entry.target.classList.remove("animate-fadeIn"); + } + }); + }; + + const observer = new IntersectionObserver(callback); + + const targets = document.querySelectorAll(".js-show-on-scroll"); + targets.forEach(function (target) { + target.classList.add("opacity-0"); + observer.observe(target); + }); + const scrollRef = useRef(null); const messages = [ "It's over Anakin! I have the high ground.", @@ -29,7 +49,7 @@ function App() { {messages.map(function (message, i) { return (
-
+

{message}

@@ -70,26 +90,9 @@ function App() { })}
diff --git a/tailwind.config.cjs b/tailwind.config.cjs index 3efce91..d63808c 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -6,7 +6,17 @@ module.exports = { "./src/**/*.{js,ts,jsx,tsx}", ], theme: { - extend: {}, + extend: { + animation: { + fadeIn: "fadeIn 1s ease-in forwards" + }, + keyframes: { + fadeIn: { + "0%": { opacity: 0 }, + "100%": { opacity: 1 } + } + }, + }, }, plugins: [ require('@tailwindcss/typography'),