我怎样才能使一个HTML滚动条在底部开始?能使、滚动条、HTML

2023-09-10 17:23:29 作者:归期

我试图让一个滚动区域的客舱,但我开始滚动条在顶部而不是底部。这意味着你可以看到所有的第一个消息,但并不是所有的新的,直到你向下滚动。这客舱将会得到很多信息,所以酒吧需要开始在底部。

这是我得那么远了jQuery,但它不工作

  $('#客舱')。每个(函数(){
                $(本).scrollTop($(本).prop('scrollHeight属性'));
            });
 

那么,如何得到一个滚动条留在涡旋的底部?

编辑:现在使用这个code。它进入围在中间,而不是底部。

  $('#客舱)。动画({
                   scrollTop的:$('#客舱')高度()},0。
                );
 
html的一个DIV样式,如何使内容滚动条隐藏,但依旧可以滚动

解决方案

好吧,我想通了。这是得到它的工作的code:

  $('#客舱)。动画({
                   scrollTop的:$(#客舱)丙(scrollHeight属性)},0。
                );
 

或非动画:

  $(#客舱)丙({scrollTop的:$(#客舱)丙(scrollHeight属性)})。
 

I'm trying to make a scrollable area for a chatbox, but my scrollbar starts at the top and not the bottom. This means you see all the first messages, but not all the new ones until you scroll down. This chatbox is going to get a lot of messages, so the bar needs to start at the bottom.

This is what I got so far in JQuery, but it's not working

$('#chatbox').each(function(){
                $(this).scrollTop($(this).prop('scrollHeight'));
            });

So how do I get a scrollbar to stay at the bottom of the scroll?

Edit: Now using this code. it goes to around the middle, but not the bottom.

$('#chatbox').animate({ 
                   scrollTop: $('#chatbox').height()}, 0
                );

解决方案

Okay I figured it out. This is the code that got it working:

$('#chatbox').animate({ 
                   scrollTop: $("#chatbox").prop("scrollHeight")}, 0
                );

Or for non-animated:

            $("#chatbox").prop({ scrollTop: $("#chatbox").prop("scrollHeight") });