gpt4 book ai didi

javascript - 同时使用 scrollTop() 两次

转载 作者:行者123 更新时间:2023-11-30 12:34:12 25 4
gpt4 key购买 nike

如何使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com