Overview
In my pursuit to optimize my web appliations, I am transitioning from standard img
tags to Next's Image
tag. While it is great for performance, making it do custom effects and styling can be frustrating.
The Problem
I am trying to add a parallax effect to a Next Image
. I was previously able to add a parallax library but that seemed to not integrate with the Image
tag.
Is there a way to add a simple parallax effect on scroll to a Next image?
My Attempts
- I've tried adding a dynamic translateY style property to the
Image
tag itself, but the browser doesn't seem to read the string interpolation.
<Image
src={url}
height={450}
width={1080}
layout="responsive"
className="object-cover"
style={{transform: 'translateY(${offset / 2}px)'}}
/>
Here is a repl.it link that you can look at.