如何让我的 scrollTo 在 table 中的列上工作,在 Javascript 中工作?

How to make my scrollTo on a column in a table working in Javascript?

我正在尝试将一列滚动到底部,但它不起作用。有人知道如何处理吗?

这是我的简单代码:

<table>
   <tbody>
       <tr>
           <td id='Trigger_td'>
               sometext
           </td>
           <td id='My_td' style='overflow:scroll;display:block;height:50vh'>
                sometext
           </td>
      </tr>
    </tbody>
</table>

在我的 .js 文件中:

  $("#Trigger_td").on("click",function(){
     //Other stuff that fill "#My_td" with content that make it overflow
     $("#My_td").get(0).scrollTo(0,$("#My_td").get(0).scrollHeight);
  });

我希望我给你所有关于它的重要信息(第一次在这里写问题)。我猜这是因为当点击触发时 My_td 还没有“准备好”滚动。我试着设置了一个 setTimeout,但是没有用。

非常感谢

你试过了吗Element.scrollIntoView()

document.getElementById('My_td').scrollIntoView();