meds
meds

Reputation: 22926

Scroll to position (javascript)

I'm trying to get javascript to scroll the page to a target position, something like:

scrollbarxpos += (targetscrollbarxpos - scrollbarxpos) / 100.0f;

And basically keep calling that line of code until scrollbarxpos = targetscrollbarxpos.

Any idea how I can go about doing this?

Upvotes: 0

Views: 4229

Answers (2)

Jeff B
Jeff B

Reputation: 30099

You can always use jQuery:

http://jsfiddle.net/jtbowden/vJmcK/

Upvotes: 0

NT3RP
NT3RP

Reputation: 15370

Have you looked at the scrollTo function? It allows you to scroll to a position on a page with x- or y- coordinates. If you want to animate the scroll, you could use some combination of setInterval and clearInterval to call scrollTo until you've reached your desire y-position.

Upvotes: 2

Related Questions