Statebox Changestate middle Wieport

How do I make a statebox open when visible in the middle of the viewport?

Wix Editor

I’m trying to make my statebox open in a new state when in the middle of the screen and close to previous state when it leaves the middle of the screen.

I tried using container boxes as to dictate when to open and close the statebox as they enter or leave the screen, but it works very poorly.

I am not super good with coding, so a nice detailed way to do it would be helpful.
I am changing statebox1 to state “open” and state “closed”

Hi, you can use the Velo event handlers onViewportEnter and onViewportLeave. Found here:

However these will run when the statebox enters the viewport and leaves, not when it is in the middle of the screen specifically.
If this is required, I would try using container boxes (sounds like you might have already tried this but just wanted to post info anyway), each a few pixels high and the same width as the multistate. Then add the onViewportEnter event handlers for both of these, with each of them setting the state to ‘open’ and also add ‘onViewportLeave’ event handlers for both boxes that sets the state to ‘closed’.

If you have tried that, what do you mean by it working poorly?
Also, an edge case you’ll need to think about is will the multistate ever be bigger than a users screen? How would you want to handle this case?