Jump to content
Search Community

Parallax images: how to position the moving image to start the parallax always from the center of another image in a container

_username7777 test
Moderator Tag

Recommended Posts

I have these two images where I want to use a parallax effect. 

I don't know what size the larger images will be, so I want to account for portrait and landscape 

 

I want to position the green box so it starts exactly centered within the larger image, and then finishes its parallax just at the top of the container 

 

const heightDiff = pImage.offsetHeight - pImage.parentElement.offsetHeight;

yPercent: -heightDiff
yPercent: heightDiff


So I've created this variable, where it calculates it dynamically, however inputting the variable in my yPercent breaks the parallax 
Is this the right idea? 

 

See the Pen abEzGjp by sophielihenry (@sophielihenry) on CodePen

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...