pixelcog / parallax.js

Simple parallax scrolling effect inspired by Spotify.com implemented as a jQuery plugin
MIT License
3.53k stars 840 forks source link

Using "sticky"element offsets parallax container #292

Open moseleyi opened 4 years ago

moseleyi commented 4 years ago

I use a wrapper with logo and navigation as a position:sticky element but I change its size when somebody scrolls past 100px to take up less space.

Unfortunately both versions of the script make the parallax-mirror to shift.

Here is the image: image

Basically onload it's aligned with the brown container. But once I start scrolling it also moves down by the difference of height of the sticky element..

wirion commented 4 years ago

I have the exact same issue. I tried without success 2 different ways to get the images to anchor to a deeper element that does not change size

carlitoselmago commented 3 years ago

I found a dirty quick way to overcome this issue:

Since the positions get updated on window->resize event you could just trigger a fake resize event. If using jquery it's as easy as calling $(window).resize(); along the event that changes you DOM element to position:fixed;

levmyshkin commented 3 years ago

$(window).resize(); can be too much, because it will stop your scroll. You can trigger parallax.js event to calculate offset again, when you sticky menu is not fixed anymore: $(window).trigger('resize.px.parallax');