Jquery - 如何将垂直滚动条截断到特定高度?

Jquery - How to cut off the vertical scroll to a specific height?

我正在使用 table2csv 和 jquery 将 HTML table 导出到 CSV。我遇到的一个问题是摆脱 table 单元格内的化身以生成干净的数据。我目前使用的解决方法是克隆 table,删除不需要的元素,将克隆的 table 的可见性设置为隐藏并将其附加到正文:

const $this = $(this)
const $table = $('#report-table')
const $title = $table.data('title')

const $tableClone = $table.clone()
$tableClone
  .attr('id', 'report-table-clone')
  .css('visibility', 'hidden')
  .find('.avatar')
  .remove()
$tableClone.appendTo('.content')

let options = {
  trimContent: true,
  filename: `${$title}.csv`
}
$this.on('click', e => {
  $('#report-table-clone').table2csv('download', options)
})

此解决方案有效,但由于隐藏的克隆 table,它使垂直高度加倍。

有什么办法可以把原来的垂直滚动条截到底部table。

我发现我可以通过将隐藏的克隆 table 的位置设置为固定并将其顶部设置为 0 来将滚动高度减半:

$tableClone
  .attr('id', 'report-table-clone')
  .css({'visibility' : 'hidden', 'position' : 'fixed', 'top' : 0})
  .find('.avatar')
  .remove()