我有一个ng-repeat,它在聊天中显示聊天消息。但是最早的聊天消息首先出现,我必须向下滚动才能看到最新的消息。我想在页面加载后结束ng-repeat即最新的聊天和向上滚动,如果需要看到旧的聊天,就像在任何其他mesaaging应用程序。
HTML:
<div class="panel-body">
<ul class="chat">
<li ng-repeat="msg in msgListing" ng- class="msg.senderid==senderidvalue ? 'left clearfix sender' : 'right clearfix reciever'">
<div class="header">
<strong ng-class="msg.senderid==senderidvalue ? 'pull-left primary-font' : 'pull-right primary-font'">
<p ng-if="msg.senderid == senderidvalue">{{currentusername}}</p>
<p ng-if="msg.senderid != senderidvalue">{{recievername}}</p>
</strong> <small ng-class="msg.senderid==senderidvalue ? 'pull-right text-muted' : 'pull-left text-muted'">
<span class="glyphicon glyphicon-time"></span>{{msg.senton}}</small>
</div>
<p class="chat-text">
{{msg.messagetext}}
</p>
</li>
</ul>
</div>
答案 0 :(得分:2)
添加值时使用scrollHeight
var scroller = document.getElementById("autoscroll");
scroller.scrollTop = scroller.scrollHeight;
}, 0, false);
&#13;
答案 1 :(得分:0)
使用ng-repeat和orderBy就像这里
<tr ng-repeat="friend in friends | orderBy:predicate:reverse">