滚动到DIV的底部? [英] Scroll to bottom of div?

查看:95
本文介绍了滚动到DIV的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的轨道一个ajax聊天,我试图让一个div滚动到底没有多少运气。

I am creating an ajax chat in rails and I am trying to get a div to scroll to the bottom without much luck.

我包裹一切都在这个DIV:

I am wrapping everything in this div:

#scroll {
    height:400px;
    overflow:scroll;
}

有没有一种方法,以保持它使用JS滚动至底部在默认情况下?

Is there a way to keep it scrolled to the bottom by default using JS?

有没有一种方法,以保持它滚动到下一个Ajax请求后?

Is there a way to keep it scrolled to the bottom after an ajax request?

推荐答案

下面是我在我的网站上使用(我没有写,我只是发现它的地方,因为我不知道Javascript的太清楚了。)

Here's what I use on my site (I didn't write it, I just found it somewhere since I don't know Javascript too well.)

var objDiv = document.getElementById("your_div");
objDiv.scrollTop = objDiv.scrollHeight;

这篇关于滚动到DIV的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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