[英]Scroll to position (javascript)
I'm trying to get javascript to scroll the page to a target position, something like: 我正在尝试使用javascript将页面滚动到目标位置,例如:
scrollbarxpos += (targetscrollbarxpos - scrollbarxpos) / 100.0f;
And basically keep calling that line of code until scrollbarxpos = targetscrollbarxpos. 并且基本上一直调用该行代码直到scrollbarxpos = targetscrollbarxpos。
Any idea how I can go about doing this? 知道我怎么能这样做吗?
Have you looked at the scrollTo function? 你看过scrollTo函数了吗? It allows you to scroll to a position on a page with x- or y- coordinates.
它允许您使用x或y坐标滚动到页面上的位置。 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. 如果要为滚动设置动画,可以使用
setInterval
和clearInterval
某种组合来调用scrollTo
直到达到所需的y位置。
You can always use jQuery: 你总是可以使用jQuery:
http://jsfiddle.net/jtbowden/vJmcK/ http://jsfiddle.net/jtbowden/vJmcK/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.