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. 1.Kali安装到移动硬盘或者U盘中~Linux系通用方法(包括Android)
  2. 【分布式】Zookeeper请求处理
  3. 三、oracle数据库成功安装步骤 Oracle数据源配置
  4. struts.xml配置详解 内部资料 请勿转载 谢谢合作
  5. ubuntu 编译源码坏境配置
  6. Guava中Predicate的常见用法
  7. Android ANR分析(2)
  8. jQuery学习笔记整理
  9. linux&amp;mac下查看端口被哪个进程占用
  10. JavaScript基础(一)
  11. ZOJ 3827 Information Entropy 水题
  12. DB天气app冲刺第八天
  13. php设计模式之单例模式
  14. junit initializationError和找不到或无法加载主类
  15. 最短寻道优先算法----SSTF算法
  16. 使用dubbo中间件的zookeeper注册中心时报错
  17. java_GPS数据处理
  18. Codeforces | CF1028C 【Rectangles】
  19. 【转贴】Linux下MySQL 5.5的修改字符集编码为UTF8(彻底解决中文乱码问题)
  20. leetcode-algorithms-6 ZigZag Conversion

热门文章

  1. js异步加载和按需加载
  2. Linux新硬盘、分区、格式化、自动挂载
  3. MySQL 查询练习记录
  4. python进阶09 MySQL高级查询
  5. Codeforces 140E(排列组合、dp)
  6. Python 开发基础-字符串类型讲解(字符串方法)-1
  7. openstack安装newton版本keyston部署(一)
  8. C#基础之运行环境
  9. Java中的日志框架
  10. pixhawk在linux(ubuntu16.04)下的开发环境搭建和源码编译