Hey guys, I need your help!
We are working on our new page and I am trying to get an scroll animation to work. I have a video on the top of the page that I want to transform on scroll. At the same time a background image is blurred. I tried getting it to work with Webflow interactions but the scroll triggers confused me too much.
The animation is loading fine but it feels a little laggy. Especially in Chrome. Safari works fine. Also Arc which is based on Chrome works fine.
Could someone look into that?
This is our page: https://cf-vierless.webflow.io
This is my code:
document.addEventListener("DOMContentLoaded", function() {
const videoContainer = document.querySelector(".hero-vertical_video");
const background = document.querySelector(".hero-vertical_image");
// Function to calculate element offsets
const calculateOffsets = () => {
videoContainerOffset = window.pageYOffset + videoContainer.getBoundingClientRect().top;
backgroundOffset = window.pageYOffset + background.getBoundingClientRect().top;
};
// Initial offset calculation
let videoContainerOffset, backgroundOffset;
calculateOffsets();
// GSAP animation
gsap.registerPlugin(ScrollTrigger);
gsap.fromTo(".hero-vertical_video", {
x: "28%",
y: "37%",
z: "0",
skewX: "0deg",
skewY: "8deg",
scaleX: 1,
scaleY: 1,
rotation: 0,
perspective: 0
}, {
x: "50%",
y: "37%",
z: "0",
skewX: "0deg",
skewY: "0deg",
scaleX: 1.4,
scaleY: 1.4,
rotation: 0,
perspective: 0,
duration: 1,
ease: "power4.out",
scrollTrigger: {
trigger: ".hero-vertical_video",
onUpdate: calculateOffsets,
start: () => "top " + videoContainerOffset + "px",
end: "top 10%",
scrub: 0.75,
toggleActions: "restart none none none"
}
});
gsap.to(".hero-vertical_image", {
filter: "blur(40px)",
scaleX: 0.75,
scaleY: 0.75,
duration: 1,
ease: "power4.out",
scrollTrigger: {
trigger: ".hero-vertical_video",
onUpdate: calculateOffsets,
start: () => "top " + backgroundOffset + "px",
end: "top 10%",
scrub: 1.5,
toggleActions: "restart none none none"
}
});
// Recalculate offsets on screen resize
window.addEventListener("resize", () => {
calculateOffsets();
});
});