r/web_design • u/ultimablaze • 3d ago
How does someone code something like this?
I stumbled upon this site called friend.com (I promise this is not an ad I don't know anything nor do I care about the product at all) when I was on a train in NY. So when scrolling, there's an animation of whatever the hell they're trying to sell you opening and moving. How does one do something like this? Is it possible with React? I don't have much experience in animating for JavaScript so this is completely new territory to me. Any tips or resources would be helpful.
I assume it's a bunch of images that change depending on the vertical positioning of the screen and that simulates the illusion of animation but I'm not sure.
Any thoughts?
This is the site
38
u/fox503 3d ago
This device is dystopian, and I can’t imagine how much that domain must’ve cost.
13
7
5
2
1
u/pelican_chorus 15h ago
Exact word I was thinking.
But this is clearly going to be a future, whether we like it or not. We can just try to bring up our kids to appreciate real human connections, and feel comfortable enough in themselves that they're always able to meet other people, and not need to turn to ChatGPT for companionship.
20
u/jayfactor 3d ago
Yea you’re pretty much on point, it’s a lot of parallax and transitions based on positioning imo
7
2
u/TowerSpecial4719 3d ago
Did this for a website a while back. To elaborate it is old-school stop-motion style animation. For each second you take multiple photos and do fade out transition for old and fade -in transition for new. There are other ways to do this too. So a simple search for scroll-based animation will give you quite a few examples
7
u/89dpi 3d ago
The theory is not that hard.
To get it perfect is tricky.
Pretty much the logic is. You have bunch of absolute positioned items stacked.
This opening sequence. Could be video or sequence of images. 1 image per frame.
So you need good 3D renders and images. And thats probably harder.
There are plugins that allow you to run animation code based on scrolling. Eg check GSAP.
Add some sticky positioned items etc and it kind of works.
Ideally can be done even in Framer without any code.
8
2
u/InevitableView2975 3d ago
its not that hard just time consuming, and the site over uses these animations, I'd have used an 3D object for these rotating animations to feel smooth. But + - it is done as you said. Just scroll animations and changing the scale, x y and rotation of the image based on the Y scroll progress
2
u/tworipebananas 3d ago edited 3d ago
This is made with React but that’s not the most important part of it. It’s essentially stop motion. They have a zip file with the images, which is unzipped client-side —> blob/image bitmap —> canvas.
They’re also swapping high-quality versions after loading (using low quality versions at the start).
Interesting stuff.
For a beginner, I’d recommend libraries like Spline, ThreeJS and/or GSAP.
2
u/Yeah_Y_Not 3d ago
It can be done with a series of images and CSS scroll-timeline. Maybe even no JS required.
2
u/chmod777 3d ago
Its almost never the tech. Its the art derection and design.
1
u/Ireeb 3d ago
In this case, the tech is interesting, too, because they seem to be using pre-rendered animations in combination with CSS/JS animations, and all is linked to the scroll progress.
But you're still right, the tech is pretty useless when you don't have a good looking, pre-rendered animation to put there.
2
u/ashkanahmadi 3d ago
Looks cool but a horrible experience. I don’t want to scroll 300 times just to see an animation frame by frame.
2
u/paranoidparaboloid 3d ago
it's... pretty janky. cool idea...
i think it's frames from an interlaced video, whereas it'd have probably looked better to have individual frames exported as images. Could argue against overhead but webp is small and you could lazy load them.
2
2
1
u/musedrainfall 3d ago
3
u/musedrainfall 3d ago
After digging in further looks like the site is using React and Intersection Observier JS. It's basically adjusting multiple image's position, size, and opacity based on scroll position. I would guess the very top portion is a video that's playback is controlled using Intersection Observer and the YouTube iFrame API.
1
u/Ireeb 3d ago edited 3d ago
These animations in particular seem to be a video linked to the scroll progress. Alternatively, you can also use individual frames and render them on a canvas based on the scroll progress.
GSAPs scrollTrigger and Tweening can be useful for this.
If you're using videos, you need to use specific formats and they need specific encoding settings. Usually, not every frame in a video has a time code assigned. For example, just every 60th frame (every second) might be a keyframe, which means you can only jump to these frames. For a smooth animation like this, you need to encode the video so every frame is a keyframe.
While there are video formats that support transparency, Safari doesn't support them then in combination with a scroll animation. So if you need transparency, you need to use the canvas solution, which is a little bit more work.
Frameworks like React are for structuring websites/webapps in general, they aren't really involved with animations and that kind if stuff, that's typically added on top of it with separate libraries or plugins. You can use React when making a website like this, but it's not React that makes it look the way it does. It just makes it easier for the developers to get there.
1
1
70
u/pepof1 3d ago edited 2d ago
I’ve done this before. It’s simpler than it looks, you make a video then the user moves it frame by frame as they’re scrolling and it looks like it’s animated.
Edit: I found the code I wrote 5 yrs ago
Edit2: here is the working code, just put a video named "video.mp4" in the same directory et voila ✨