脚本宝典收集整理的这篇文章主要介绍了angular2 滚动条到底部,发送消息框,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1、htML代码
<div #scrollMe style="height: 100px; overflow: scroll; background: #fff; border: 1px solid #aaa;">
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
<p>test</p>
</div>
<button (click)="goToScrollBottom()">发送</button>
2、组件代码
@H_894_360@import {component} From '@Angular/core';
// 滚动条使用组件
import {ElementRef, AfterViewChecked, ViewChild} from "@angular/core";
@Component({
selector: 'app-root',
templateUrl: './app.COMponent.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewChecked {
constructor() {
}
@ViewChild("scrollMe")
// 获取元素
public myScrollContainer: ElementRef;
// 其实上面两句代码可以写成:
// @ViewChild("scrollMe") myScrollContainer;
ngAfterViewChecked() {
this.scrollToBottom();
}
// 方法调用
goToScrollBottom() {
this.scrollToBottom();
}
scrollToBottom() {
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
}
}
如何判断滚动条到底部了
if ((this.myScrollContainer.nativeElement.scrollTop + this.myScrollContainer.nativeElement.clientHeight) == this.myScrollContainer.nativeElement.scrollHeight) {
// 如果到底不了 调用接口加载数据,追加到数组中。
}
以上是脚本宝典为你收集整理的angular2 滚动条到底部,发送消息框全部内容,希望文章能够帮你解决angular2 滚动条到底部,发送消息框所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。