简体   繁体   English

滚动条位置

[英]Scrollbar position

My question is related the following fiddle. 我的问题与以下小提琴有关。 http://jsfiddle.net/PGuB5/84/ http://jsfiddle.net/PGuB5/84/

In this fiddle, Click the add row button, the row will be added. 在此小提琴中,单击添加行按钮,将添加该行。 The scroll bar will be displayed automatically after some content added. 添加一些内容后,滚动条将自动显示。

$('.scrollToBottom').on('click', function() {
    $(".scrollbox").scrollTop($(".scrollbox")[0].scrollHeight);
});

Now I scroll the content at the bottom of the container and click the add row button. 现在,我滚动容器底部的内容,然后单击添加行按钮。 The scroll bar position is stay in the bottom. 滚动条的位置位于底部。

I want, If I click the add row button, the scroll bar need to move to top. 我想要,如果我单击添加行按钮,则滚动条需要移到顶部。

For scrolling to top, use : 要滚动到顶部,请使用:

$('.scrollbox').scrollTop(0);

Updated Fiddle 更新小提琴

$('.addrow').on('click', function() {
    $('.scrollbox').append(newline);
    $('.scrollbox').scrollTop(0);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM