我正在使用一个bootstrap固定头表现在我想在我渲染到taht页面时设置滚动位置

时间:2017-10-11 11:11:21

标签: jquery css

固定标题具有以下类

<style>
    .table-fixed tbody
    {
        height: 580px;
        display: block;
        overflow-y: auto!important;
        border: solid 1px #c1c1c1;
        position: relative;
        /*width: 100%;*/
    }

    .table-fixed thead, .table-fixed tbody tr
    {
        display: table;
        width: 100%;
        table-layout: fixed;

    }

    .table-fixed thead
    {
        width: calc(100%-1em);
        border: solid 1px #c1c1c1;
    }

</style>

现在我想在特定的锚标签上设置滚动条的位置

像这样的表       部分Numberabc1
aff-200abc2
abc 2 descabc 3 desc
a1000

1 个答案:

答案 0 :(得分:0)

<div>
<table id="my_table">
    <tr id='row_1'><td>1</td></tr>
    <tr id='row_2'><td>2</td></tr>
    <tr id='row_3'><td>3</td></tr>
    <tr id='row_4'><td>4</td></tr>
    <tr id='row_5'><td>5</td></tr>
    <tr id='row_6'><td>6</td></tr>
    <tr id='row_7'><td>7</td></tr>
    <tr id='row_8'><td>8</td></tr>
    <tr id='row_9'><td>9</td></tr>
</table>
</div>

var container = $('div'),
scrollTo = $('#row_8');

container.animate({
    scrollTop: scrollTo.offset().top - container.offset().top + 
container.scrollTop()
});