左边是我要滚动的内容...它滚动了一点点然后停止了。它似乎每次都滚动相同的量。
当我尝试滚动到的内容位于 div 中时,我正在尝试使用 jQuery 获取 scrollTop 以处理页面加载。当前的实现没有做任何事情
JavaScript
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>
$(document).ready(function (){
//$(this).animate(function(){
$('html, body').animate({
scrollTop: $("#test4").offset().top
}, 2000);
//});
});
</script>
html
<div class="row">
<div class = "span12">
<div class = "row">
<div class = "span2">
<div style="height:480px;font:12px Georgia, Garamond, Serif;overflow:auto;">
<div id = "test1">Test1</div>
<div id = "test2">Test2</div>
<div id = "test3">Test3</div>
<div id = "test4">Test4</div>
</div>
</div>
<div class = "row">
<div class = "span8">
Other content on the page
</div>
</div>
</div>
</div>
</div>
最佳答案
我已经稍微更改了您的代码,您可以 find the fiddle here .
这是我用过的js代码:
$('.sss').animate({
scrollTop: $(".test5").offset().top
}, 2000);
这里
$('.sss')
是持有侧链的持有者
关于javascript - 在 div 中滚动时如何在 jQuery 中使用 scrollTop?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13171191/