开发者

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 call开发者_开发百科ing that line of code until scrollbarxpos = targetscrollbarxpos.

Any idea how I can go about doing this?


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.


You can always use jQuery:

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜