An animation framework prototype/proof-of-concept (PoC) that allows you to animate in section elements on a webpage with many sections. Sections follow a specific template and have certain requirements as well.
This set of requirements is for a particular project so it is very specific & in its entirity might not be applicable to other projects, but parts of it might be useful to repurpose.
- each page has multiple sections
- each section has the following elements: background colour, content (heading, text, image) and optional background footer
- only the 1st section will have a background header, if sticky header (mislabelled "nav bg") is set to
true
it should kick in as you begin to scroll down the page; but not on render when page is in original position, as 1st section has a static header already - you should be able to animate in elements with different timings and direcions (section contents)
- animations to be triggered by scrolling into sections; once animated in, they do not need to animate out on reverse scroll
- a section can also dictate what the sticky header should be like when that section is active (example: sticky header/"nav bg" background colour should match the section's background colour)
- on window resize, calculations should update in an optimised way so everything works correctly (not yet implemented)
- this PoC is limited to desktop resolution (not responsive, doesn't support mobile/tablet views)
- sections should be a reuseable component
- section background colours should blend with other sections automatically
- use react.js &
IntersectionObserver
- vite.js
v4.3
- react.js
v18.2
- Intersection Observer API
- Fork & clone this repo
- Have Node
v18
(or newer), - Get
yarn
ornpm
- In terminal go to DIR &
cd animation-frameework
- Run
yarn
ornpm install
- On successful installation, run
yarn dev
ornpm run dev
- Finally, open http://localhost:5173 in your browser to view the app.
- cool CSS colours & their names here
- helpful: https://css-tricks.com/an-explanation-of-how-the-intersection-observer-watches/
- helpful codepen from the article above (my fork, fixed an issue)
- ChatGPT 3.5 assisted; my demo #1 of functionality required
- my demo #2 making the nav know which section it is over
- FIXME: when a section exceeds the viewport height greatly, I can't the IntersectionObserver to behave correctly like with other sections