开发者

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


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


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 :)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜