Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress stops working on window resize #145

Open
ncpilla opened this issue Mar 3, 2023 · 2 comments
Open

Progress stops working on window resize #145

ncpilla opened this issue Mar 3, 2023 · 2 comments

Comments

@ncpilla
Copy link

ncpilla commented Mar 3, 2023

When resizing from mobile to desktop or visa-versa. The progress stops working and only returns 0 or 1. This doesn't seem to happen when you resize just a little bit. Only large changes.

You can see it happening by resizing the example here in chrome or firefox (edge seems to work for some reason) https://russellsamora.github.io/scrollama/progress/

@JidduAlexander
Copy link

I think what happens in this case is that the resize causes the trigger line to be outside of the window, at which point the trigger line is no longer functional. When you force a scrollama.resize() after resizing the window then also the trigger line is redrawn inside in the window and progress works.

The issue is not only for the progress, it also happens in sticky-side. When you resize the screen to very small the trigger no longer happens when you scroll up and down.

@NateWr
Copy link

NateWr commented Oct 16, 2023

I'm not certain what the cause was, but calling a debounced scrollama.resize() fixed this problem for me.

My assumption is that the built-in resize observer in 3.0 is responding too quickly, and the layout reflow hasn't finished yet, and that's causing some kind of problem. It could be that one or more of my steps is in an intermediary state that makes the trigger line outside of the window, as @JidduAlexander suggested.

For others, here is the code I used:

import scrollama from 'scrollama';
import { debounce } from 'throttle-debounce'

const scroller = scrollama()
  .setup(...)
  .onStep...

window.onresize = debounce(1000, scroller.resize)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants