javascript - 同时使用 scrollTop() 两次

标签 javascript jquery

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

相关文章:

javascript - 需要在另一页上 $save()

jquery - qTip2 自定义 css 问题

jquery - 使用jquery为每个设置id

javascript - 根据下拉列表中选择的值切换 <div>

javascript - 在 selectOneMenu 更改时在同一窗口中打开对话框

php - 部署没有源代码的网站

javascript - 以编程方式加载 chrome 扩展

javascript - 带 (+) 键的按键功能不起作用

javascript - 正则表达式删除 { } 之外的所有内容

javascript - 使用 hasOwnProperty 的合适/推荐方法是什么?