McKayla
McKayla

Reputation: 6949

How far can I scroll?

I'm making a simple script that scrolls to the bottom.

for (var i = 0; i < 100; i++)
    window.scroll.after(i * 5, [0, i]);

The above script works perfectly, other then it doesn't scroll all the way, because it's only told to scroll 100 pixels down.

How can I tell how far down you can scroll? Or can I not?

Upvotes: 1

Views: 320

Answers (2)

Matt Ball
Matt Ball

Reputation: 359946

You can just scroll to some ridiculously large value.

for (var i = 0; i < 4294967296; i++)
    window.scroll.after(i * 5, [0, i]);

I'm not sure what browser or library you're using that supports scroll.after() like that, though.

https://developer.mozilla.org/en/window.scroll

Upvotes: 1

imsky
imsky

Reputation: 3289

Get the document height and use that as the "bottom" value: http://james.padolsey.com/javascript/get-document-height-cross-browser/

Upvotes: 4

Related Questions