IjzerenHein / famous-flex

Animatable layouts, FlexScrollView & widgets for famo.us.
MIT License
279 stars 44 forks source link

relative scroll position #93

Closed ranmacar closed 9 years ago

ranmacar commented 9 years ago

Hello,

I am trying to determine my scroll position on a scale from 0-1. Have trouble understanding what the scrollOffset value in the event represents. Thought it goes from 0 to negative container width, but seems its not that simple.

Is there a simple way to get the scroll position in this range?

Thanks!

IjzerenHein commented 9 years ago

Hi,

First of all, which version of famous-flex are you using? I'm asking because v0.3 now returns the absolute scrollOffset in the events. The scrollOffset is in pixels btw, not percentage. If you want to convert it into percentage, you could wrap it in a 'SizeAwareView' in order the width/height and convert scrollOffset to a percentage.

cheers

ranmacar commented 9 years ago

Thanks for the quick response,

I am using the 0.3. Noticed the scrollOffset is in pixels, but didn't quite understand what it represents. What I'd want to achieve is a centered scrollView, which starts with the middle-ish element in the middle, at which point the calculated offset is 0.5. And by scrolling to the sides it varies between 0 on the left and 1 on the right.

ranmacar commented 9 years ago

Works now, with scrollView.scroll(scrollViewSize/2) and onScroll with the calculation relative = (e.scrollOffset) / (scrollViewSize - e.size[0])