anomareh
anomareh

Reputation: 5584

jQuery scroll to target from current position not top

I'm looking for away to scroll the window to a specified position from the window's current position, NOT from the top of the window.

From the bit of playing around I've done I can't find a way to do this. I've also tried messing around with the scrollTo plugin and it exhibits the same behavior. They all reset the window's position to the top left, then scroll to the target location. Is it even possible?

Thanks.

EDIT I made an embarrassingly dumb mistake. One little missed return false; :s

Upvotes: 1

Views: 4800

Answers (3)

AUSteve
AUSteve

Reputation: 3258

You could just skip up/down the page using good ol' anchor tags:

<A href="#furtherdown">go down</a>
...
...
<a name="furtherdown />

This will scroll the page so that the <a name> tag is at the top of the viewport.

Upvotes: 0

jrharshath
jrharshath

Reputation: 26583

You can find your current position using pageXOffset and pageYOffset.

Then you can use the scrollTo plugin to scroll to another position relative to your current one.


EDIT: You should use $(document).scrollTop(), like @David says. jQuery likey :)

Upvotes: 1

David Hellsing
David Hellsing

Reputation: 108500

You can get the distance scrolled using $(document).scrollTop(). Just add that number to your desired position.

Upvotes: 1

Related Questions