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 (