如何使用 animate ({ scrollTop() })
同时滚动多个 DIV?
例如,如果我运行下面的 goTOP(){;
函数。我想滚动到页面顶部,同时滚动到 #studentName
TABLE 的顶部。
<table class="table table-striped table-hover" id="studentName">
<thead>
<tr>
<th class="col-md-2">ID</th>
<th class="col-md-2">Subject</th>
</tr>
</thead>
<tbody></tbody>
</table>
#studentName 有一个滚动条[EDIT]
#studentName{
overflow-y: scroll;
max-height: 100px;
}
jQuery:这是我迄今为止尝试过的方法。没有按预期工作。
function goTOP(){
$('html, body').animate({ 'scrollTop' : 0 }, 700);//go top of page
$('html, body').animate({ 'scrollTop' : $('#studentName').first().offset().top }, 100); // go to top level of this DIV
}
最佳答案
function goTOP(){
$('html, body').animate({ 'scrollTop' : 0 }, 700);//go top of page
$('#studentName tbody').animate({ 'scrollTop': 0 }, 100); // go to top level of this DIV
}
关于javascript - 同时使用 scrollTop() 两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26630974/