最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - AJAX chat, auto scroll window - Stack Overflow

programmeradmin5浏览0评论

Duplicate

Scrolling Overflowed DIVs with JavaScript


I have an AJAX chat that outputs the messages to a div with overflow: auto so if it gets too long, the scroll bar es up. Is there is a way to have it auto scroll to the bottom whenever a new message is added? Preferably using jQuery?

Duplicate

Scrolling Overflowed DIVs with JavaScript


I have an AJAX chat that outputs the messages to a div with overflow: auto so if it gets too long, the scroll bar es up. Is there is a way to have it auto scroll to the bottom whenever a new message is added? Preferably using jQuery?

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Apr 12, 2009 at 1:25 roflwaffleroflwaffle 30.7k21 gold badges76 silver badges97 bronze badges 1
  • @Brandon: this question has already been asked and answered; i've added a link to the existing discussion at the top of yours. – Shog9 Commented Apr 12, 2009 at 1:29
Add a ment  | 

4 Answers 4

Reset to default 5

it'd be done with the following line

$("#youChatDiv").attr({ scrollTop: $("#youChatDiv").attr("scrollHeight") });

what this does is set the scroll to the height of the own element

just call that with every new message :)

cheers

Property scrollHeight is the ideal but it is not part of the W3C.

For further understanding visit:

http://yelotofu./2008/10/jquery-how-to-tell-if-youre-scroll-to-bottom/

If each message is in a separate element (div, paragraph etc.), you can just call scrollIntoView

This Jquery plugin will help you.

Jquery ScrollTo plugin demo page

发布评论

评论列表(0)

  1. 暂无评论