From: ryan [#1]
25 Mar 2009
To: ALL
nerds, to the nerd mobile!
i have a scroller that scrolls a page to the bottom, loads the next page and scrolls that before loading the next page ad infinitum. the speed of this scroller is controlled by specifying the duration of the animation.
the problem is, my maths is shit so i'm struggling to pull a formula out of the variables i have that gives a consistent scroll speed for both very long documents and very short docs.
the vars i have are...
docH = doc height (ie. the total length of the whole document)
winH = window height (ie. the browser pane)
speed_mod = a multiplier. lets say this is 1 for the moment, but it'd be nice if i could add a degree of flexibility.
at the moment i'm trying to do...
( ( docH / winH ) * 1000 ) * ( speed_mod * ( docH / winH ) )
which isn't entirely satisfactory. the actual speed is about right but there is a fair bit of variance between pages. there is no reward for the helper beyond the knowledge that they helped me to help myself stop sucking at maths.
and possibly a warm glow of satisfaction.
EDITED: 25 Mar 2009 by RYAN
From: Spanjab [#2]
25 Mar 2009
To: ryan [#1] 25 Mar 2009
2 + 2 = 5 (for very large values of 2)
I hope that helps?
From: Astrum Mortis (AM) [#3]
25 Mar 2009
To: ryan [#1] 26 Mar 2009
Edit: That was all bollocks, so might this be:
You need an average time to view a given amount of viewable page (T).
T(Speed_mod+(docH/winH))
So lets say it takes 10 seconds to view 100 units of page, your winH is 1050 units and your docH is 5000 units.
10(1050/100)(1+(5000/1050))
105(1+4.7619)
105*5.7619 = 604.9995s << Duration of animation
~8.3 units per second
increase the speed mod for slower people...
10(1050/100)(1.5+(5000/1050))
105(1.5+4.7619)
105*6.2619 = 657.4995s
~7.6 units per second
longer doc...
10(1050/100)(1+(6000/1050))
105(1+5.7143)
105*6.7143 = 705.0015s
~8.5 units per second
much longer doc...
10(1050/100)(1+(100000/1050))
105(1+95.2381)
105*6.7143 = 10105.005s
~9.8 units per second
Still not sure, but I'm outta time again
EDITED: 25 Mar 2009 by AM
From: roBurky [#4]
25 Mar 2009
To: ryan [#1] 26 Mar 2009
What about:
(docH - winH) * speed_mod
You take the size of the document, and remove the portion of it that's being displayed at the start to find the distance you have to scroll. That should relate directly to the length of time you want to spend scrolling.
So with a document of height 100, and a window of height 10, you have 90 units of height to scroll through, and will spend 90 units of time scrolling through it, at 1 unit height per 1 unit of time.
With a document of height 50, and a window of height 1, you have 49 units of height to scroll through, and will spend 49 units of time scrolling through it, at 1 unit of height per 1 unit of time.
From: Jon [#5]
25 Mar 2009
To: ryan [#1] 26 Mar 2009
Gah, I normally love thins kind of thing. Especially when there's no reward other than being able to help someone.
However, my brain is still mostly mush and today it seems particularly bad. Even uploading photos to flickr has been a challenge and I don't know if I'll log on for the op :(
Sorry.
From: ryan [#6]
26 Mar 2009
To: ALL
cheers guys, i'm going to have a play with those.
i think i was definitely adding too much variance with all the multiplication, and most likely trying to come up with something too complicated.
it's slightly embarrassing being 2/3 programmer (web apps aren't proper programming, i'm told. then again the people who tell me that also assure me that C# isn't a proper programming language either.) and being so ridiculously poor at maths. :x
From: ryan [#7]
26 Mar 2009
To: ALL
for what it's worth, i combined both methods.
AM's didn't have enough variance between the high&low speed modifiers applied, robs was offset too far, so i just mashed them together and it seems to work perfectly. \o/
From: Astrum Mortis (AM) [#8]
26 Mar 2009
To: ryan [#7] 26 Mar 2009
Good news!
I was thinking, for the very large doc size examples you would need to make the modifier very large too, so perhaps it should be tied to docH somehow, but no matter, you got it done somehow :)