【问题标题】:Facing issue during changing the height depending on the screen size in angular6根据angular6中的屏幕尺寸更改高度时面临的问题
【发布时间】:2018-09-30 17:31:24
【问题描述】:

我正在使用 HostListener 来根据屏幕大小更改高度,但在加载页面期间,“event.target.innerHeight”稍后给出未定义我将在更改浏览器高度时获得该值,所以我已经初始化了值。最初,如果用户在大屏幕上浏览,该值不会改变

 Here is the code

  myInnerHeight = 524;         //Laptop screen
  mypaletteHeight = 471;       //Laptop screen

@HostListener('window:resize', ['$event'])
  onResize(event) {
    if (event.target.innerHeight > 680) {
     this.myInnerHeight = 727;     //bigger screen
     this.mypaletteHeight = 674;    //bigger screen
    } else {
      this.myInnerHeight = 524;      //Laptop screen
      this.mypaletteHeight = 471;    //Laptop screen
    }
  }

HTML

<div class="card h-100" [style.min-height.px]="myInnerHeight" >
....
     <div class="sub2" id="sub2" [style.height.px] = "mypaletteHeight">
     .
     .
      </div>
</div>

我正在使用 Angular 6 和引导程序 4。

如何在页面加载时获取屏幕尺寸的值。请帮我解决这个问题

【问题讨论】:

  • 你想要达到什么目的?这难道不是用 CSS 可以实现的吗?
  • 媒体查询FTW!

标签: javascript jquery angularjs angular bootstrap-4


【解决方案1】:

你试过 window.screen.height & window.screen.width

获取文档客户端宽度&高度,document.documentElement.clientWidth & document.documentElement.clientHeight

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-10
    • 2011-06-15
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多