zoukankan      html  css  js  c++  java
  • angular5自适应窗口大小

    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);
        }
    }
    
    
  • 相关阅读:
    springboot2 + prometheus + grafana 监控整合
    vs code 快捷键总结
    java8 concurrecy
    java8 localdatetime timestamp 转换
    有意思的网站
    评价搜索引擎质量
    转载一篇文章
    csdn 站点使用
    百度站点平台
    好的文章聚合站点
  • 原文地址:https://www.cnblogs.com/jecyhw/p/8308362.html
Copyright © 2011-2022 走看看