我怎样才能使一个HTML滚动条在底部开始? [英] how can I make a html scrollbar start at the bottom?

查看:96
本文介绍了我怎样才能使一个HTML滚动条在底部开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

  $('#客舱)。动画({
                   scrollTop的:$('#客舱')高度()},0。
                );
 

解决方案

好吧,我想通了。这是得到它的工作的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") });

这篇关于我怎样才能使一个HTML滚动条在底部开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆