簡體   English   中英

根據angular6中的屏幕尺寸更改高度時面臨的問題

[英]Facing issue during changing the height depending on the screen size in angular6

我正在使用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和bootstrap 4。

如何在頁面加載時獲取屏幕尺寸的值。請幫助我解決此問題

您是否嘗試過window.screen.height和window.screen.width

要獲取文檔客戶端的寬度和高度,請選擇document.documentElement.clientWidth和document.documentElement.clientHeight

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM