Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Restyle fix parallax #75

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/components/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,35 @@ export default function Home() {
useEffect(() => {
// parallax effect
const handleParallax = (entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// speed of the parallax effect
const backgroundSpeedFactor = 0.5;
entries.forEach((entry) => {

window.addEventListener("scroll", () => {
// get window height
let windowHeight = window.innerHeight;

const scrolled =
window.scrollY - entry.target.offsetTop - windowHeight / 2;

// background position
document.querySelector(".polaroids-sky").style.backgroundPositionY =
`-${scrolled * backgroundSpeedFactor}px`;
document.querySelector(
".polaroids-bottom",
).style.backgroundPositionY =
`-${scrolled * backgroundSpeedFactor}px`;
});
}
});
};

const observer = new IntersectionObserver(handleParallax, {
threshold: 0.1,
});

//element to observe
const target = document.querySelector(".end-scroll");
observer.observe(target);
}, []);
window.addEventListener('scroll', () => {
// get window height
let windowHeight = window.innerHeight;
Expand Down
Loading