嗨,我正在 angularjs 中构建一个聊天应用程序,我希望聊天框自动向下滚动。我正在使用我放入指令的这个例子:http: //jsfiddle.net/atRkJ/
它按原样工作,但是当我将它与 ng-repeat 一起使用时,它不起作用。
.html 文件
<ul id="chat" style="height:300px; overflow:auto" scroll-if>
<li data-ng-repeat="messageinfo in messages" >
<div class="message-date">
{{messageinfo[0]}}
</div>
</li>
</ul>
指令.js
.directive('scrollIf', function() {
return{
restrict: "A",
link: function(scope, element, attributes) {
var chat_height = $('#chat').outerHeight();
console.log(chat_height);
$('#chat').scrollTop(chat_height);
}
}
});
有什么帮助吗?谢谢