angular5自适应窗口大小
2024-08-30 03:40:41
import {AfterViewInit, Directive, ElementRef, HostBinding, HostListener, Inject, Input, Renderer2} from '@angular/core';
import {DOCUMENT} from '@angular/common';
@Directive({
selector: '[fixWindow]'
})
export class FixWindowDirective implements AfterViewInit {
private bodyEl;
@Input() marginBottom = 24;
@Input() minWidth = 400;
@HostBinding('style.height.px') height = 400;
@HostListener('window:resize') onResize() {
// 窗口自适应大小
let height = this.bodyEl.getBoundingClientRect().height - this.el.nativeElement.getBoundingClientRect().top - this.marginBottom;
if (height < this.minWidth) {
height = this.minWidth;
}
this.height = height;
}
constructor(private el: ElementRef, private ren2: Renderer2, @Inject(DOCUMENT) private doc: Document) {
}
ngAfterViewInit() {
this.bodyEl = this.doc.querySelector('body');
// fix bug: Expression has changed after it was checked.
setTimeout(() => this.onResize(), 500);
}
}
最新文章
- 1.Kali安装到移动硬盘或者U盘中~Linux系通用方法(包括Android)
- 【分布式】Zookeeper请求处理
- 三、oracle数据库成功安装步骤 Oracle数据源配置
- struts.xml配置详解 内部资料 请勿转载 谢谢合作
- ubuntu 编译源码坏境配置
- Guava中Predicate的常见用法
- Android ANR分析(2)
- jQuery学习笔记整理
- linux&;mac下查看端口被哪个进程占用
- JavaScript基础(一)
- ZOJ 3827 Information Entropy 水题
- DB天气app冲刺第八天
- php设计模式之单例模式
- junit initializationError和找不到或无法加载主类
- 最短寻道优先算法----SSTF算法
- 使用dubbo中间件的zookeeper注册中心时报错
- java_GPS数据处理
- Codeforces | CF1028C 【Rectangles】
- 【转贴】Linux下MySQL 5.5的修改字符集编码为UTF8(彻底解决中文乱码问题)
- leetcode-algorithms-6 ZigZag Conversion