Window.scrollY always returning 0 when referenced from within object event

advanced-prototyping

#1

Hey all -

I’m running into an issue when trying to setup autobuild animations on scroll. The issue is, when I try to reference an object’s position versus the current position on the page, the Window.scrollY reference always returns 0.

The idea is that I want the object to hide on load and then appear once the user has scrolled to where it’s visible…but in this situation, the case never triggers because Window.scrollY is returning 0.

Yet if I create a second shape and have it set text for itself on click to Window.scrollY, that resolves properly.


#2

OnLoad I’d expect the window to not be scrolled at all thus I’d also expect Window.scrollY to be 0. Working as intended, I believe.

Are you saying that the repeated firing of the OnLoad event later on isn’t working as expected after the user has scrolled a bit?

I can’t quite follow what you want to achieve but this seems like something that should be on the OnWindowScroll event, perhaps?


#3

On the initial load, yes the window.scrollY should be 0.

But the way I have it set up, it should be triggering on a loop, and checking for the current Window.scrollY position every time to see if the condition has been satisfied.

The idea is that once the user has scrolled far enough down the page (window.scrollY + window.height) for the widget in question to be fully visible, I want it to animate in, like so:


#4

Hi there,

As Nathan mentions, using the OnWindowScroll event may be needed at some point. If you want to continue with the current approach where the bulk of interactions are under OnLoad, one idea is to create an OnWindowScroll case that dynamically moves a hot spot to the Window.ScrollY value (https://www.screencast.com/t/kwJIGajyk). You could then target the hot spot’s y-coordinate (which is set dynamically) in your interactions instead of directly referencing the browser window’s scroll position that’s tracked in the initial OnLoad (https://www.screencast.com/t/zAyUQEwS7ndq).

Here’s a sample file showing that:

OnWindowScroll.rp (50.6 KB)


unlisted #5