如何在div底部修复滚动条?

我正在做一个简单的聊天应用程序,我想在底部修复一个div的滚动条。就像这样 在此处输入图像描述

加载索引页面时,滚动条必须位于底部

这是我的style.css

body{ font: 0.9em monospace; } .messages{ border: 1px solid #ccc; width: 250px; height: 210px; padding: 10px; overflow-y:scroll; } .message{ color: slategrey; } .message p{ margin: 5px 0; } .entry{ width: 260px; height: 40px; padding: 5px; margin-top: 5px; font: 1em fantasy; } 

这是我的index.php

        

我怎么设置这个,请帮帮我..谢谢

试试这个jquery:

 $(".messages").animate({ scrollTop: $(document).height() }, "slow"); return false; 

这里是小提琴: http : //jsfiddle.net/EX6vs/

或指的是元素的高度(许多同意是正确的方式),如下:

 $(".messages").animate({ scrollTop: $(this).height() }, "slow"); return false; 

这里是小提琴: http : //jsfiddle.net/69vpnyu1/

你想要这样的东西,其中box是包含你聊天的div。 在页面加载时调用这些。

 var box = document.getElementById('Box'); box.scrollTop = box.scrollHeight; 

发布新聊天时也会调用此方法。

我使用谷歌应用引擎创建了一个类似的应用程序。 你可以在这看看它

http://chatter-now.appspot.com/

随意使用它作为参考。 虽然您使用的是php,但视觉方面可能会有所帮助。

您可以使用jQuery来完成,因为您可以在此处看到演示:

http://jsfiddle.net/9S92E/

 function loadchatval(){ $.post('loadchat.php',function(data){ $('#load_chat').html(data); $("#load_chat").animate({ scrollTop: $(document).height() }, "slow"); return false; }); } 

下面的代码行总是在整个页面的底部滚动垂直滚动条。

 $("html, body").animate({ scrollTop: $(document).height() }, "fast"); 

下面的代码行总是在名为“ daViewerContainer ”的可滚动div容器的底部滚动垂直滚动条。

 $("#daViewerContainer").animate({ scrollTop: $(document).height() }, "fast"); 

我修复了这个:

 $(document).scrollTop($(document).height()); 

一切都取决于你如何配置div,然后使用div作为文档。 但是这个也很好用粘性页脚。