angular6 + primeng^5.2.7对话框抖动问题
一 .html代码
内容
二.component.ts
//引入dialog对象
import { Dialog } from 'primeng/dialog';
//引用p-dialog组件
@ViewChild('dialog') dialog: Dialog;
//在钩子函数中复写Dialog的center方法
ngAfterViewInit() {
this.dialog.center = function () {let elementWidth = this.domHandler.getOuterWidth(this.containerViewChild.nativeElement);let elementHeight = this.domHandler.getOuterHeight(this.containerViewChild.nativeElement);if (elementWidth === 0 && elementHeight === 0) {this.containerViewChild.nativeElement.style.visibility = 'hidden';this.containerViewChild.nativeElement.style.display = 'block';elementWidth = this.domHandler.getOuterWidth(this.containerViewChild.nativeElement);elementHeight = this.domHandler.getOuterHeight(this.containerViewChild.nativeElement);this.containerViewChild.nativeElement.style.display = 'none';this.containerViewChild.nativeElement.style.visibility = 'visible';}let viewport = this.domHandler.getViewport();let x = Math.max(Math.ceil((viewport.width - elementWidth)) / 2, 0);let y = Math.max(Math.ceil((viewport.height - elementHeight)) / 2, 0);// 解决抖动问题if (!this.containerViewChild.nativeElement.style.left ||!this.containerViewChild.nativeElement.style.top ||Math.abs(this.containerViewChild.nativeElement.style.left - x) > 5 ||Math.abs(this.containerViewChild.nativeElement.style.top - y) > 5) {this.containerViewChild.nativeElement.style.left = x + 'px';this.containerViewChild.nativeElement.style.top = y + 'px';}};
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
