1

你好我有这个html代码:

 <style type="text/css">
    .container{
        width: 450;
        height: 400;
        border:1px solid;
        border-radius: 6px;
        background: #000;
    }
    .name{
        border-bottom:1px solid;
        background: #FFF;
    }
    .div_lines{
        max-height: 360px;
        background: #000;
        color:#FFF;
        overflow: auto;
        vertical-align: top;
    }
    </style>
    <div class="container">
    <div class="name">show</div>
    <div class="div_lines">
    <code class="lines">
        <div class="line">1</div>
        <div class="line">2</div>
        <div class="line">3</div>
        <div class="line">4</div>
        <div class="line">5</div>
        <div class="line">6</div>
        <div class="line">7</div>
        <div class="line">8</div>
        <div class="line">9</div>
        <div class="line">10</div>
        <div class="line">11</div>
        <div class="line">12</div>
        <div class="line">13</div>
        <div class="line">14</div>
        <div class="line">15</div>
        <div class="line">16</div>
        <div class="line">17</div>
        <div class="line">18</div>
        <div class="line">19</div>
        <div class="line">20</div>
        <div class="line">21</div>
        <div class="line">22</div>
        <div class="line">23</div>
        <div class="line">24</div>
        <div class="line">25</div>
        <div class="line">26</div>
        <div class="line">27</div>
        <div class="line">28</div>
    </code>
    </div>
    </div>

但我想知道的是,有没有办法改变向下滚动,这样当我到达显示滚动条的地步时,我需要向上滚动以查看过去的数据而不是向下滚动?就像命令提示符一样,它将显示最后插入的行,您需要向上滚动才能查看预览信息。

4

1 回答 1

1

每当插入另一行时,让这段 javascript 代码运行:

var lines=document.getElementsByClassName('line');
lines[lines.length-1].scrollIntoView();
于 2013-02-26T02:13:12.780 回答