向下滚动 - 反向

时间:2013-02-26 02:09:17

标签: jquery html css

你好,我有这个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>

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

1 个答案:

答案 0 :(得分:1)

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

var lines=document.getElementsByClassName('line');
lines[lines.length-1].scrollIntoView();