Javascript autoscroll angularjs不';好像不行
嗨,我正在用angularjs构建一个聊天应用程序,我希望聊天框能自动向下滚动。我正在使用这个例子,我在一个指令中加入了这个例子: 它的工作原理是,但当我使用它与ng重复它不工作 html文件Javascript autoscroll angularjs不';好像不行,javascript,jquery,angularjs,angularjs-directive,angularjs-ng-repeat,Javascript,Jquery,Angularjs,Angularjs Directive,Angularjs Ng Repeat,嗨,我正在用angularjs构建一个聊天应用程序,我希望聊天框能自动向下滚动。我正在使用这个例子,我在一个指令中加入了这个例子: 它的工作原理是,但当我使用它与ng重复它不工作 html文件 <ul id="chat" style="height:300px; overflow:auto" scroll-if> <li data-ng-repeat="messageinfo in messages" >
<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>
有什么帮助吗?当您调用代码时,感谢您:
var chat_height = $('#chat').outerHeight();
console.log(chat_height);
$('#chat').scrollTop(chat_height);
您的ng repeat未运行并完成其渲染,但返回的outerHeight
不正确
当ng repeat
完成时,必须运行代码。为此,您可以定义另一个指令:
.directive('scrollItem',function(){
return{
restrict: "A",
link: function(scope, element, attributes) {
if (scope.$last){ // If this is the last item, trigger an event
scope.$emit("Finished");
}
}
}
});
使用它:
<li data-ng-repeat="messageinfo in messages" scroll-item>
调用代码时:
var chat_height = $('#chat').outerHeight();
console.log(chat_height);
$('#chat').scrollTop(chat_height);
您的ng repeat未运行并完成其渲染,但返回的outerHeight
不正确
当ng repeat
完成时,必须运行代码。为此,您可以定义另一个指令:
.directive('scrollItem',function(){
return{
restrict: "A",
link: function(scope, element, attributes) {
if (scope.$last){ // If this is the last item, trigger an event
scope.$emit("Finished");
}
}
}
});
使用它:
<li data-ng-repeat="messageinfo in messages" scroll-item>