Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
rgfx

overflowed elements messing up my offset

Recommended Posts

Hi, Messing around with some parallax effects and noticed that my overflow-ed elements are throwing off my offset. Can I get offset of an element within the event somehow or a correct offset?

 

Thanks

 

 

 

See the Pen 41ca73b1a7f0578bbc6eb229f8881185 by rgfx (@rgfx) on CodePen

Link to post
Share on other sites

Don't use offsetX/Y for that. It's kind of like .position() in jQuery, and will include padding. That's where you get 30 extra pixels from. It also doesn't take any transforms into account. So if your box was scaled, it would still report the offset as if your box wasn't scaled, throwing all your coordinates off.

 

To get the mouse position relative to your box, use clientX/Y and subtract the box's boundingClientRect from it.

 

 

  • Like 6
Link to post
Share on other sites

@OSUblake Thank pal,

 

I was messing around with slight rotations as well things were not going very well clientX/Y feels like butter.

  • Like 2
Link to post
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.

×